untypedef?

untypedef?

Post by Dragan Cvetkovi » Sat, 12 Apr 2003 23:46:10



                Hi,

I am facing a problem trying to compile a program on a several different
platforms (Solaris 2.6, 7, 8 and 9, AIX 4.x, Linux). Namely, the function
getsockname(3) expects the third argument to be a pointer to a socklen_t
type, but my problems is that socklen_t is e.g. not defined on Solaris 2.6
and that AIX (at least version 4.2) expects the argument to be a pointer to
size_t type. OK, at the moment I just put pointer to int there and it (of
course works) but gives me a warning.

Now if socklen_t were a macro, I would be able to #undef it and then
#define again according to the OS in question, but is there anything
similar available for typedefs? Untypedef would be nice to have :-) And
also a way to check if something is typedef-ed other then by compiler error
generated.

Any suggestions?

Bye, Dragan

P.S. I have conditional compilation in my code based on the OS but I'll
rather not distinguish by OS version. Too many #if #else #endif :-(

--
Dragan Cvetkovic,

To be or not to be is true. G. Boole      No it isn't.  L. E. J. Brouwer

 
 
 

untypedef?

Post by Valentin Nechaye » Sun, 13 Apr 2003 14:43:17


DC> Subject: untypedef?

It doesn't exist.

DC> I am facing a problem trying to compile a program on a several different
DC> platforms (Solaris 2.6, 7, 8 and 9, AIX 4.x, Linux). Namely, the function
DC> getsockname(3) expects the third argument to be a pointer to a socklen_t
DC> type, but my problems is that socklen_t is e.g. not defined on Solaris 2.6
DC> and that AIX (at least version 4.2) expects the argument to be a pointer to
DC> size_t type. OK, at the moment I just put pointer to int there and it (of
DC> course works) but gives me a warning.

DC> Now if socklen_t were a macro, I would be able to #undef it and then
DC> #define again according to the OS in question, but is there anything
DC> similar available for typedefs? Untypedef would be nice to have :-) And
DC> also a way to check if something is typedef-ed other then by compiler error
DC> generated.

With these problems, better is to use own macro or typedef, defined
similar to following:

#if NATIVE_SOCKLEN_T_DEFINED
#define MY_SOCKLEN_T socklen_t
#elif AIX
##define MY_SOCKLEN_T size_t
...
#endif
...

MY_SOCKLEN_T l;
l = sizeof sa;
rc = getsockname( s, (struct sockaddr*) &sa, &l );

DC> P.S. I have conditional compilation in my code based on the OS but I'll
DC> rather not distinguish by OS version. Too many #if #else #endif :-(

So you need to distinguish OS version also. Or you can check presence
of socklen_t using tests as in autoconf tool, and add checking on OS type
or on tests result what alternative is appropriate (int, size_t, etc.)

-netch-