Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Run Time ask for size

Posted on 2000-05-04
6
Medium Priority
?
196 Views
Last Modified: 2010-04-02
How I can in run time ask from different computers about size of int.
0
Comment
Question by:Michael Vai
  • 3
  • 2
6 Comments
 
LVL 4

Expert Comment

by:pellep
ID: 2778347
sizeof(int)
0
 

Author Comment

by:Michael Vai
ID: 2778502
Without sizeof(int)
0
 
LVL 2

Accepted Solution

by:
abesoft earned 80 total points
ID: 2778568
Seems like a strange request.  Why don't you want to use sizeof()?

Anyway, here it goes:

int sizeInBits;
for (sizeInBits = 1; (1u << sizeInBits) > 1; ++sizeInBits)
    cout << (1u << sizeInBits) << endl;
cout << "An int is " << sizeInBits << " bits" << endl;

This works under VC++.  I believe that the definition of << is standard enough for this to work on any compiler.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Expert Comment

by:abesoft
ID: 2778575
Sorry.  Should have written that as:

int sizeInBits;
for (sizeInBits = 1; (1u << sizeInBits) > 1; ++sizeInBits)
    ;
cout << "An int is " << sizeInBits << " bits" << endl;
0
 

Author Comment

by:Michael Vai
ID: 2778894
what means "1u"
0
 
LVL 2

Expert Comment

by:abesoft
ID: 2780446
u = unsigned
l = long

You can tag a constant with either or both of these qualifiers.  In effect, we measured the size of an unsigned int, not an int.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

886 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question