#ifdef __SunOS_5.10

A

Andrew Gabriel

I want to pick up the OS release during compilation in order to
make up for something which is missing from a header file in a
certain release. The Sun C compiler provides a built in predefinition

__`uname -s`_`uname -r`

and as an example, echo __`uname -s`_`uname -r` gives:

__SunOS_5.10

So in my code I have:

#ifdef __SunOS_5.10
/* typedef missing from headerfile */
typedef char *x;
#endif

However, this fails because the "." is treated as the end of the
token, and the excess tokens on the line generate a warning. I've
tried some other varients such as

#ifdef "__SunOS_5.10"

#ifdef __SunOS_5\.10

but these don't work either. Is there a way to do this?
I'm trying to avoid adding any further command line -D's as that's
generated by complex makefiles which I'm not allowed to change.
 
M

Malcolm McLean

Andrew Gabriel said:
I want to pick up the OS release during compilation in order to
make up for something which is missing from a header file in a
certain release. The Sun C compiler provides a built in predefinition

__`uname -s`_`uname -r`

and as an example, echo __`uname -s`_`uname -r` gives:

__SunOS_5.10

So in my code I have:

#ifdef __SunOS_5.10
/* typedef missing from headerfile */
typedef char *x;
#endif

However, this fails because the "." is treated as the end of the
token, and the excess tokens on the line generate a warning. I've
tried some other varients such as

#ifdef "__SunOS_5.10"

#ifdef __SunOS_5\.10

but these don't work either. Is there a way to do this?
I'm trying to avoid adding any further command line -D's as that's
generated by complex makefiles which I'm not allowed to change.

I suspect that you have two definitions there, one a string and one a
number.
You need to put in a #if uname-r == 5.10. However uname-r probably won't be
the identifier to use, Sun will have provided something with a name like
VERSION_
 
K

Keith Thompson

I want to pick up the OS release during compilation in order to
make up for something which is missing from a header file in a
certain release. The Sun C compiler provides a built in predefinition

__`uname -s`_`uname -r`

and as an example, echo __`uname -s`_`uname -r` gives:

__SunOS_5.10

No, the Sun C compiler doesn't provide this particular predefined
symbol. It couldn't, since such a symbol is illegal.

<OT>
"cc -### nosuchfile.c" will show you which symbols are predefined.
One of those symbols is "__SunOS_5_10", which is a legal identifier.
</OT>

Note that identifiers starting with "__" are reserved to the
implementation. Here, it's being defined by the implementation, which
is perfectly correct. If you tried to define such an identifier
yourself, you'd be infringing on the implementation's namespace, with
potentially dangerous consequences.

If you have questions about C, this is the right place. If you have
questions about the behavior of Sun's C compiler, you'll get better
help in comp.unix.solaris.
 
A

Andrew Gabriel

No, the Sun C compiler doesn't provide this particular predefined
symbol. It couldn't, since such a symbol is illegal.

OK, the manpage is wrong then ;-)
<OT>
"cc -### nosuchfile.c" will show you which symbols are predefined.
One of those symbols is "__SunOS_5_10", which is a legal identifier.
</OT>

Thanks, that works!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,162
Latest member
GertrudeMa
Top