Re: preprocessing statements
"Keith Thompson" <kst-u@mib.org> wrote in message
news:lnprr7r0xp.fsf@nuthaus.mib.org...
> "Bill Cunningham" <nospam@nspam.com> writes:
>> I have been thinking about hiding headers from my compiler's
>> preprocessor and allowing others to be shown. I want to use the most used
>> and add others is necessary. Would this be how it is properly done. I
>> want
>> to ask ahead of time because what I do might work but it might not be the
>> "correct" or standard way.
>>
>> #include <stdio.h>
>> #include <stdlib.h>
>> #ifdef LINUX
>> #include <unistd.h>
>> #include <sys/types>
>> #include <sys/stats.h>
>> #include <fctnl.h>
>> #endif
>>
>> Is the #endif needed at the end of this case ?
>
> One more thing that you didn't ask about (but probably should have):
>
> How do you expect the symbol LINUX to be defined? Since that
> identifier must be available for use in programs, an implementation is
> not allowed to pre-define it. There may be other symbols that are
> predefined (if you're trying to determine whether you're on a Linux
> system); which symbols those might be is a question for another forum.
>
> If you're defining it yourself, that's fine, but you didn't show that.
>
> Also, you appear to be trying to write code that will use things
> declared in those implementation-defined headers if you're on a Linux
> system, but will still compile and work properly otherwise. Such
> things are doable, but the nature of the questions you've been asking
> here suggest to me that this is a more advanced topic than you're
> ready for.
>
Perhaps so but the code above didn't work. This code I wrote did. The
question is did I do it correctly.
#include <stdio.h>
#include <stdlib.h>
#ifdef linux
#ifndef linux
#undef linux
#include <unistd.h>
#include <sys/types.h>
#include <sys/stats.h>
#include <fctnl.h>
#endif
#endif
I compiled a simple program asking sizeof to show through printf the
size of a long double. I haven't defined linux to use those sys call headers
yet though so that part of the header is untested. But the directives
blocked out the mentioned OT headers to compile a simple C program. I
must've did something right.
Bill
|