liteserver / binn

Binary Serialization

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Reserved #defines

csstup opened this issue · comments

Compiling binn on native IBM compiler.

"binn.c", line 36.9: 1506-236 (W) Macro name _BIG_ENDIAN has been redefined.
"binn.c", line 37.10: 1506-296 (S) #include file <machine/endian.h> not found.

In the case of the native compiler, the symbols in question are defined as:

#define __BIG_ENDIAN__ 1
#define _BIG_ENDIAN 1

Also, note that symbols with a leading underscore are considered reserved and should not be defined. Might want to make your endian detection code platform independent.

"Each name that begins with an underscore is reserved to the implementation for use as a name in the global namespace."

Hi!

Thank you for your contribution.

Please checkout the updates and make a new test. Then tell me if it was solved.

Sure! I'll give it a try tomorrow. Thanks for the quick response!.

Hi Corey,

Is it OK now?

Sorry for taking so long to reply. Changes in job.

I took your latest update and made the following changes:

#if defined(__APPLE__) || defined(_WIN32)
#define __BIG_ENDIAN      0x1000
#define __LITTLE_ENDIAN   0x0001
#define __BYTE_ORDER    __LITTLE_ENDIAN
#elif defined (_AIX)
#include <sys/machine.h>
#define __BIG_ENDIAN      BIG_ENDIAN
#define __LITTLE_ENDIAN   LITTLE_ENDIAN
#define __BYTE_ORDER      BYTE_ORDER
#else
#include <endian.h>
#endif

Here's the relevant part of <sys/machine.h> on AIX:

/*
 * Definitions for byte order,
 * according to byte significance from low address to high.
 */
#define LITTLE_ENDIAN   1234    /* least-significant byte first (vax)         */
#define BIG_ENDIAN      4321    /* most-significant byte first (IBM, net)     */
#define PDP_ENDIAN      3412    /* LSB first in word, MSW first in long (pdp) */

#define BYTE_ORDER      BIG_ENDIAN

I can compile without issue now. I'm testing the result now.

Thanks!

Running the tests, it looks like at least some of it assumes you're on LE.

So on BE, the test_endianess() function asserts immediately.

void test_endianess() {
  unsigned short vshort1, vshort2;
  unsigned int   vint1, vint2;
  uint64 value1, value2;

  printf("testing endianess... ");

  /* tobe16 */
  vshort1 = 0x1122;
  vshort2 = tobe16(vshort1);
  assert(vshort2 == 0x2211);
  vshort2 = tobe16(vshort2);
  assert(vshort2 == vshort1);

Should we make the tests endian agnostic?

Hi Corey,

Thank you!

Indeed, the test should test the endianess conversion on both architectures. The expected values are different for each. The expected values should be unmodified on BE.

I updated the endianess test case.

Do you want to send a pull request with your contribution for AIX?

If yes, it must contain only those modifications on binn.c to be accepted. It should not contain formatting differences on the file.

If you don't want then I can insert them.

I'll give the test case a try.

My machine doesn't have access to the internet, so I can't do git work with it. Its probably just as easy for you to add the changes.

Thanks!

OK, I updated it.

The leading underscores were used because the endianess checking was based on the Google Chrome source, and it is used on Linux. But it is really becoming weird now. At least they are not exported on binn.h

The macros were renamed