Solved

Run Time ask for size

Posted on 2000-05-04
6
188 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 20 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

813 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now