Is there a standardised way to get type sizes in bytes in C++ Compilers? -


I was thinking that there are some standardized methods of type size in memory in the pre-processor phase- in macro form, < Code> Size () does not cut it.

If they do not have a standardized method, then what are their traditional methods that use most IDEs?

Can anybody think of getting such data from any other way?

I think I can build two steps, produce a test program and feed it back to IDE, but

thoughts:

Edit:

I just want to be able to swap the code

  #ifdef / #endif  

It seems that an IDE or underlying compiler can define that information under some macros? Make sure that the preprocessor does not get information on the functions of an actual machine code generation, but the IDE and the compiler do it, and they call the pre-processor and declare stuff in advance.

Go ahead

I imagine that there was a conceptual concept:

C ++ is a standard of the committee which calls for every type ( Probably only giving those origins to C ++) to the compiler IDE is a header file, which is included by default, which announces size in memory used in the original type, such as:

  #define CHAR_SIZE 8 #define INT_SIZE 32 #define SHORT_INT_SIZE 16 #define FLOAT_SIZE 32 / / etc  

Is there any flaw in this process?

Also edit in addition to

Multi-stage construction platform problem, perhaps this standard can give the mandate to compile a simple program shown by Laqui and run by default In this way, whatever type of shape it gets, the same machine will compile the code in the second or 'normal' construction phase.

Apologies:

I am using 'variable' instead of 'type'

Depending on your build environment, you can write utility programs that generate headers included in other files:

  int main (void ) {Out = make_header_file (); // fprintf defined by you (outside, "#ifndef VARTYPES_H \ n # defined VARTYPES_H \ n"); Size_t intsize = sizeof (int); If (intsize == 4) fprintf (outside, "#define INTSIZE_32 \ n"); And if (intsize == 8) fprintf (outside, "# INTSIZE_64 defined \ n"); // ..... and fprintf (outside, "$ INTSIZE_UNKNOWN defined \ n"); }  

Of course, edit this as appropriate and then "vartypes.h" is required everywhere you need these definitions.

Edit : Alternatively:

  fprintf (outside, "#define INTSIZE_% D \ n", (sizeof (int) / 8)); Fprintf (outside, "# defined INTSIZE% d \ n", (sizeof (int) / 8));  

Note the lack of underscores in the second one - first creates INTSIZE_32 which can be used in #ifdef . The second creates INTSIZE which can be used, for example four bit [INTSIZE];

Alert : This will only work with 8-bit char Most modern home and server computers will follow this pattern; However, some computers can use different sizes of char


Comments