login
Header Space

 
 

gcc 2.2.2d: htonl, etc. problem with -O and netinet/in.h

Score:
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
Date: Monday, August 31, 1992 - 11:14 am

Hello.  With gcc 2.2.2d, htonl, htons, ntohl, or ntohs,
everything works fine except when you #include <netinet/in.h>
and compile with -O.  In this case, bytes/words are not swapped.
This can be demonstrated with the following program:

#include <netinet/in.h>
int main(void)
{
    printf("%08x, %08x, %04x, %04x\n",
           htonl(0x01020304), ntohl(0x01020304),
           htons(0x0102), ntohs(0x0102));
    return 0;
}

The output of this program should be

04030201, 04030201, 0201, 0201

If you compile this with gcc -O, you will get

01020304, 01020304, 0102, 0102

Although it seems that this should be an error with the inline
assembly routines defined in netinet/in.h, I'm not sure whether
that is really the problem or not.  Either not including
<netinet/in.h> or not using -O produces correct results.


-- 
                                Jay Berkenbilt (ejb@ERA.COM)
                                Engineering Research Associates
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
gcc 2.2.2d: htonl, etc. problem with -O and netinet/in.h, Jay Berkenbilt, (Mon Aug 31, 11:14 am)
speck-geostationary