Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C++ and Visual C++ > C++ Programming
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
C++ Programming General discussions for the C++ language. For questions specific to Microsoft's Visual C++ variant, see the Visual C++ forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C++ Programming section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old October 14th, 2005, 10:03 PM
Registered User
 
Join Date: Oct 2005
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Integer Size

I have need to program on a cross-platform basis. I am coding on Windows/OSX/Linux, unfortunately the size of certain data types can vary between these OS's and compilers.

I have found a way to ensure the size of the datatypes on Windows: __intn and on OSX: uintn/sintn, but I am wondering if there is a ISO standard size defined numeric type?

Thanks for your time,
Miq
Reply With Quote
  #2 (permalink)  
Old October 19th, 2005, 10:15 PM
Registered User
 
Join Date: Oct 2005
Location: , , .
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

use sizeof method
int i=0;
cout<<sizeof i<<endl;
there is no ISO standard.
Reply With Quote
  #3 (permalink)  
Old October 20th, 2005, 01:34 AM
Authorized User
 
Join Date: Mar 2005
Location: Wagga Wagga, NSW, Australia.
Posts: 60
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to Alan-LB Send a message via Yahoo to Alan-LB
Default

should be
....sizeof(i)....

Alan


Reply With Quote
  #4 (permalink)  
Old October 20th, 2005, 04:43 AM
Registered User
 
Join Date: Oct 2005
Location: , , .
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

no sir,
it's --> sizeof i

Reply With Quote
  #5 (permalink)  
Old October 21st, 2005, 12:33 AM
Authorized User
 
Join Date: Mar 2005
Location: Wagga Wagga, NSW, Australia.
Posts: 60
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to Alan-LB Send a message via Yahoo to Alan-LB
Default

sizeof() is a function (not a method) and needs the brackets to hold the argument i.

If you omit the brackets it will compile but the output will not show the size of the integer.

Please post the code of a program you have written and got to run showing the correct output with sizeof used as you say.

Alan


Reply With Quote
  #6 (permalink)  
Old October 21st, 2005, 06:54 PM
Registered User
 
Join Date: Oct 2005
Location: , , .
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

No,sizeof is a operator,not function or method
you can use like that:
1) sizeof( object );
2) sizeof( type_name );
3) sizeof object; //

Reply With Quote
  #7 (permalink)  
Old November 6th, 2005, 09:04 PM
Authorized User
 
Join Date: Nov 2005
Location: Chennai, Tamil Nadu, India.
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to Paramesh
Default

We can use the sizeof operator in the ways described by phoenix.

The only thing we must remember is to put an extra space after sizeof.
For example, if we use:
sizeof i
then it will return the size of i.
But if we use it as:
sizeofi
then only an error message will pop up saying that
sizeofi undeclared.

Regards,
Paramesh.

"Don't walk behind me; I may not lead.
 Don't walk in front of me; I may not follow.
 Just walk beside me and be my friend."
Reply With Quote
  #8 (permalink)  
Old November 6th, 2005, 10:31 PM
Authorized User
 
Join Date: Nov 2005
Location: , , .
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

sizeof is an OPERATOR:
Here is the heading from a well known tutorial on C++:
"SIZE OF - AN OPERATOR BY ITSELF . . . sizeof is an operator, not a function. If you apply it to a type, it must be used with the parenthesized form, but if you apply it to a variable you can use it without parentheses . . ."


Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Integer I/O in assembly kaycg BOOK: Professional Assembly Language 2 May 11th, 2007 05:00 AM
text vs integer paul20091968 Access VBA 2 February 13th, 2007 10:50 PM
testing integer rjonk XSLT 2 July 27th, 2006 03:11 PM
Integer Check awais_syed VB.NET 2002/2003 Basics 2 December 18th, 2004 02:04 AM
integer overflow partaola Beginning VB 6 2 March 17th, 2004 09:01 AM



All times are GMT -4. The time now is 10:34 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.