ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Is it valid to have structure variable declartion inside compiler flag in C.
For exnample ENABLE_IPV6 is compiler option
struct {
int a;
#ifdef ENABLE_IPV6
char *ipv6;
#endif
}ipv6;
It is valid (you could as well try it), but some terms should be corrected:
ENABLE_IPV6 is a 'preprocessor symbol', not a 'compiler option'
'char *ipv6;' is a 'structure-member definition, not a 'variable definition'
(Also it is really unclear what this structure is supposed to represent.)
Hi,
Its causing random crash when i am using this strucutre in another source file.Isit due to preporocessoring is hapening first in source file then in header file?
Source code where i am using this structure is also under preporocessor directive.
Hi,
Its causing random crash when i am using this strucutre in another source file.Isit due to preporocessoring is hapening first in source file then in header file?
Source code where i am using this structure is also under preporocessor directive.
Crashes, by my definition occur in code when you try to run it. But you could have a different meaning.
A point I'd like to clarify here would be:
Is the code compiling, and this crash is when you try to run?
Or is the code failing to compile, and your complaint is about that?
If (a) is the situation, then Nevemteve's link shows you information about the debugger. Also there are some links in my signature for blogs about the same topic.
If (b) is the situation, then perhaps you can post the compile errors here.
You have already been asked to debug (gdb) your program. Also Electric Fence might be useful, as your problem might very well related with malloc'ed memory. https://en.m.wikipedia.org/wiki/Electric_Fence
It seems compiler optmization creating problem when structure variable declartion were put in compoler flag
How do you know that?
You have not provided any details at all about the problem, but simply insist it is a preprocessor or compilet related problem, but without giving any useful information that would help others understand the problem.
Please use the links provided above to debug the program and learn what is really happening.
Please review the Site FAQ for guidance in posting your questions and general forum usage. Especially, read the link in that page, How To Ask Questions The Smart Way. The more effort you put into understanding your problem and framing your questions, the better others can help!
I remove all malloc calloc in that code even pointer also.But when i put compiler option it is rashing and in other case it is not.
Strucutre declariion is present in header file and that header file included in muliple source files.
Source files also have macro to use those strcutre variable.
Well, you have a bug (most likely numerous bugs) in your program. That cannot be solved without seeing the code. Problem is your code is way too big to simply insert here, so I suggest creating an mcve. https://stackoverflow.com/help/mcve
(Or just compress your source into a .tgz file and attach as file).
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.