Solved

Run Time ask for size

Posted on 2000-05-04
6
192 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: 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

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!

Question has a verified solution.

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

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…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
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.

728 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