Good evening,
I'm trying to make a simple test in visual C++ 6 - one which will not fail - to see if:
1) The current machine is running in little or big endian format;
2) If an inputed value from a given file is also in little or big endian format.
As for question #1, I've found a script in Google which goes like this:
int is_big_endian(void)
{
union {
uint32_t i;
char c[4];
} bint = {0x01020304};
return bint.c[0] == 1;
}
Problem: I'm getting the value of 0 in my machine. Is this right?
I'm calling the routine to a parameter int *endian like this:
*endian = is_big_endian();
For uint32_t I'm posting the following code in my file stdintvc.h:
#ifndef _INC_STDINTVC
#define _INC_STDINTVC
/* For some reason, Microsoft Visual C/C++ doesn't have a 'stdint.h' */
/* file to define the following 'intxx_t' and 'uintxx_t' types. This */
/* is by no means a complete 'stdint.h' replacement. I'll add things */
/* in as I need them. */
typedef signed char int8_t;
typedef unsigned char uint8_t;
typedef short int16_t;
typedef unsigned short uint16_t;
typedef int int32_t;
typedef unsigned int uint32_t;
typedef __int64 int64_t;
typedef unsigned __int64 uint64_t;
#endif
Dispite the fact that this issue is already confusing, there's the matter of the 32 and 64 bits machines...
Can we start a study on this thread about this subject?
Kind regards,
JKepler
I'm trying to make a simple test in visual C++ 6 - one which will not fail - to see if:
1) The current machine is running in little or big endian format;
2) If an inputed value from a given file is also in little or big endian format.
As for question #1, I've found a script in Google which goes like this:
int is_big_endian(void)
{
union {
uint32_t i;
char c[4];
} bint = {0x01020304};
return bint.c[0] == 1;
}
Problem: I'm getting the value of 0 in my machine. Is this right?
I'm calling the routine to a parameter int *endian like this:
*endian = is_big_endian();
For uint32_t I'm posting the following code in my file stdintvc.h:
#ifndef _INC_STDINTVC
#define _INC_STDINTVC
/* For some reason, Microsoft Visual C/C++ doesn't have a 'stdint.h' */
/* file to define the following 'intxx_t' and 'uintxx_t' types. This */
/* is by no means a complete 'stdint.h' replacement. I'll add things */
/* in as I need them. */
typedef signed char int8_t;
typedef unsigned char uint8_t;
typedef short int16_t;
typedef unsigned short uint16_t;
typedef int int32_t;
typedef unsigned int uint32_t;
typedef __int64 int64_t;
typedef unsigned __int64 uint64_t;
#endif
Dispite the fact that this issue is already confusing, there's the matter of the 32 and 64 bits machines...
Can we start a study on this thread about this subject?
Kind regards,
JKepler