Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / November 2007

Tip: Looking for answers? Try searching our database.

Problems with sizeof function

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Fran - 02 Nov 2007 13:41 GMT
sHi!

I have a very strange problem with the behaviour of the sizeof command. I
have tested it in vc6,vc 2001 and vc 2003. The problem is quite simple.

When I made a sizeof to the next struct, it returns that the size is 40
instead of 38. I consider that a short is 2 bytes, float 4 bytes, unsigned
long 4 byte, unsigned short 2 bytes. If i add all the size of the fields it
must be 38 but sizeof says that is 40.

The struct is the next:

typedef struct
{
short est;   
short numbe1;   
float dst;   
float Line;           
unsigned long tmp;
float tmp1;            
float tmp2;       
unsigned long tck;   
unsigned long tl;
unsigned short  dp;
unsigned short  ldact;   
unsigned short  lnc;
}test;

If I remove one unsigned short field, the size change to 36, but if made
size of (unsigned short) it return 2.

This is the other "crazy" struct:

typedef struct
{
short est;   
short numbe1;   
float dst;   
float Line;           
unsigned long tmp;
float tmp1;            
float tmp2;       
unsigned long tck;   
unsigned long tl;
unsigned short  dp;
unsigned short  ldact;   
}test;

I'm getting crazy, any idea??

Thank you very much for your help.

The structure is the next:
Cholo Lennon - 02 Nov 2007 14:18 GMT
This is a common question. Take a look to:

http://groups.google.com/group/microsoft.public.vc.language/browse_frm/thread/8e
7400441b97eb1e/72c336cb677db72c?lnk=gst&q=struct+s

izeof#72c336cb677db72c

Regards

--
Cholo Lennon
Bs.As.
ARG

> sHi!
>
[quoted text clipped - 49 lines]
>
> The structure is the next:
Mark Salsbery [MVP] - 02 Nov 2007 19:45 GMT
You may want to read the "Remarks" section here as well:

http://msdn2.microsoft.com/en-us/library/83ythb65(VS.80).aspx

Mark

Signature

Mark Salsbery
Microsoft MVP - Visual C++

> sHi!
>
[quoted text clipped - 50 lines]
>
> The structure is the next:

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.