Solved

Run Time ask for size

Posted on 2000-05-04
6
190 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
Independent Software Vendors: 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
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…

756 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