title: Linux: ntohl does not work correctly
body: <p>I have a project that needs to build on Windows, Linux, and VxWorks. The project is built on Linux and Windows but cross compiled for VxWorks. To handle endianness across multiple platforms, it uses ntoh.h. The Linux machine is little endian but ntohl doesn't swap in my program. </p>
  
  <p>I wrote a test program that directly includes in.h. That swaps appropriately. 
  I wrote another test program that just includes the ntoh.h. That swaps appropriately. Both test programs link to lib64/libc.so.6. </p>
  
  <p>However, when I compile my project, ntohl doesn't swap. I can't break on ntohl using gdb "break ntohl" command. When building, I see <strong>LITTLE ENDIAN</strong> warning (see below) and do not see the <strong>"SHOULDNT BE HERE"</strong> error.</p>
  
  <p>Please help. I don't understand why this problem is occurring. </p>
  
  <p>Below is ntoh.h: </p>
  
  <pre><code>#ifndef __ntoh__
  #define __ntoh__
  
  #include "basic_types.h"
  
  #ifdef WIN32
      #include &lt;winsock2.h&gt;
  #elif LINUX
      #include &lt;netinet/in.h&gt;
  
      //This is here to determine what __BYTE_ORDER is set to in netinet/in.h.
      // Not in original code 
      #if __BYTE_ORDER == __BIG_ENDIAN
      #warning BIG ENDIAN BYTE ORDER!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
      #endif 
  
      //This is here to determine what __BYTE_ORDER is set to in netinet/in.h. 
      // Not in original code
      #if __BYTE_ORDER == __LITTLE_ENDIAN
      #warning YAY LITTLE ENDIAN!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
      #endif 
  #else
  
    #error SHOULDNT BE HERE     //added for debugging purposes
    #define ntohl(x)        (x)
    #define ntohs(x)        (x)
    #define htonl(x)        (x)
    #define htons(x)        (x)
  
  #endif
  
  #endif // __ntoh__
  </code></pre>
  
  <p>Part of my compile command: </p>
  
  <pre><code>g++ -DDAU_PARSER -DNO_MT -DTEST_CLOCK -DLINUX  -g -Irelease/include -Irelease/include/Record_Data/ -Irelease/include/Utility -o dauParser DAU_Support_Tools/src/dau_parser.cpp DAU_Support_Tools/src/dau_parser_write_data_to_file.cpp Utility/src/Messaging/Communications/Message.cpp Utility/src/time_type.cpp Utility/src/collectable.cpp Utility/src/clist.cpp Utility/src/clock.cpp Utility/src/test_clock.cpp Utility/src/mutex.cpp Utility/src/ntoh.cpp ... 
  </code></pre>
  
  <p>The error is generated by the following lines:</p>
  
  <pre><code>int deadbeef = 0xDEADBEEF; 
  printf("TESTING DEADBEEF %x %x\n", deadbeef, ntohl(deadbeef) ); 
  </code></pre>
  
  <p>The output from those two lines produce same output. 
      TESTING DEADBEEF deadbeef deadbeef  </p>