Click here to Skip to main content
15,891,657 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

what does it mean if something is declared like:
#define __something__
?

How do i know whether i can use it in another file? I have tried some arguments from different libraries to read in my c code, but haven't figured out, on what it really depends.
For instance i have the kernel.h or compiler.h (gcc 4.5.2) file included, but it is not possible to read any of its arguments. I get error "arg undeclared...". On the other hand some header-files work perfectly to read their defined arguments into my c code and print them out.



[edit]
I take the first arguments from different header-files, which are similarly defined in the header-files, and want to print them with printf.
Argument of kernel.h:
#ifndef _LINUX_KERNEL_H
#define _LINUX_KERNEL_H

And Argument of _G_config.h:
#ifndef _G_config_h
#define _G_config_h 1

In the first case i can't even compile the code, i get error message:
error: expected expression before ‘)’ token
when i do:
printf("%p\n",_LINUX_KERNEL_H);

This code works perfectly when i compile it with the argument of the _G_config.h file.
[/edit]
Posted
Updated 12-Apr-12 22:26pm
v2
Comments
Richard MacCutchan 13-Apr-12 6:36am    
We would need to see a bit more of the code around the line that throws the error. Given what you have shown above I am not sure that you really understand what these statements are for; maybe you need to spend some more time with your C++ reference manual. Why are you trying to print a #define variable with a %p format specifier?
Member 8811020 13-Apr-12 8:02am    
i'm afraid there is no more code then those given lines. I just include the two libraries and make the printf statement, that is all.
I'll have to spend some more time with the reference, i guess. So far i don't really understand the type of a #define statement.
Much thanks for your help.

1 solution

Lines such as this are used by the preprocessor to include or exclude sections of source code in a module. Thus:
C++
#define __something__

#if defined(__something__)
// this source code will be included
#else
// this source code will NOT be included
#endif

As to your second question it is not clear what you mean. Any errors such as error "arg undeclared..." will depend on the part of the source module that they point to, so without seeing the piece of code that raises the error it's impossible to say why it is occurring.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 12-Apr-12 12:11pm    
Enough to get OP started, my 5.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900