Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Brobanx

Quickie

This topic is 5634 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Which C++ header file contains the sizes (in bytes or bits) of the standard simple data types (char, short, int, long, float, double, long double)? I need this info to make a header file that will work with different compilers (a neat template class that could help remove unneccessary derefencing).

Share this post


Link to post
Share on other sites
Advertisement
cout << sizeof(char) << endl;
cout << sizeof(int) << endl;

[edited by - Abob on January 19, 2003 10:57:41 PM]

Share this post


Link to post
Share on other sites
Will this work?

  
#include <iostream>

using namespace std;

int main()
{
cout << "int: " << sizeof(int) << endl;
cout << "bool: " << sizeof(bool) << endl;
cout << "long: " << sizeof(long) << endl;
cout << "short: " << sizeof(short) << endl;
cout << "char: " << sizeof(char) << endl;
cout << "long double: " << sizeof(long double) << endl;

return 0;
}


results are:

  
int: 4
bool: 1
long: 4
short: 2
char: 1
long double: 8

Share this post


Link to post
Share on other sites
No, I need the values at compile-time so that the preprocessor can handle them. I know in climits there's all the constants I need for integers and chars, but I need some way to find out how many bits are in floats / doubles at COMPILE-TIME (and it varies with different compilers so I can't just assume a double is 8 bytes or anything like that).

[edited by - Brobanx on January 19, 2003 11:08:19 PM]

Share this post


Link to post
Share on other sites
I think you''re looking for for integer values and for floating points. Both are in the std namespace.

Share this post


Link to post
Share on other sites
Could this work?

    
#define intSize sizeof(int)

#define longSobuleSize sizeof(long double)

...


[edited by - HunterTKilla on January 19, 2003 12:12:09 AM]

Share this post


Link to post
Share on other sites
The preprocessor doesn''t recognize sizeof. Although, the original problem I''m trying to solve can be easily overcome using the boost::call_traits library.

Share this post


Link to post
Share on other sites
quote:
Original post by Brobanx
The preprocessor doesn''t recognize sizeof.

Of course. The preprocessor is just like a text replace utility.

hmm... what kind of code construct you are trying to do?

Share this post


Link to post
Share on other sites
I always thought sizeof was evaluated at compile-time. Why exactly won''t it work for you again? Is there a reason the preprocessor needs to know what the size of types are?

Share this post


Link to post
Share on other sites
I''m confused as to why sizeof is no good here? It is the proper operator. I think that maybe you should read the first few chapters of your C++ book again Brobanx.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!