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: 2 1355
This is a common question. Take a look to: http://groups.google.com/group/micro...gst&q=struct+s
izeof#72c336cb677db72c
Regards
--
Cholo Lennon
Bs.As.
ARG
"Fran" <Fr**@discussions.microsoft.comwrote in message news:19**********************************@microsof t.com...
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:
You may want to read the "Remarks" section here as well: http://msdn2.microsoft.com/en-us/lib...65(VS.80).aspx
Mark
--
Mark Salsbery
Microsoft MVP - Visual C++
"Fran" <Fr**@discussions.microsoft.comwrote in message
news:19**********************************@microsof t.com...
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:
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Sona |
last post by:
I understand the problem I'm having but am not sure how to fix it. My
code passes two char* to a function which reads in some strings from a
file and copies the contents into the two char*s. Now...
|
by: kimimaro |
last post by:
hi below is my save function that is used to placed data from the C program
to a text file for future usage.
void save()
{
FILE *save;
int i = 0;
save=fopen("employeerecord.txt", "a+");
|
by: Henk |
last post by:
Hi Guys,
(see actual code below)
I wrote a little program that is supposed to read a file (input.txt)
into memory (using a stack) and then reverse the file and display it to
output. It works,...
|
by: Mike |
last post by:
Hi,
I am new to C and having problems with the following program.
Basically I am trying to read some files, loading data structures into
memory for latter searching.
I am trying to use structres...
|
by: Sheldon |
last post by:
Good day Everyone,
I am a still very new at learning C and I have thrown myself in the
deep end. I started with a simple program and kept widening the scope.
This has taught me many things about...
|
by: roguefeebo |
last post by:
I'm very new to programming so be gentle, :(
Essentially what I would like to do is to have a single function to be able to create a dynamic array of pointers to a struct so that I can have a...
|
by: patrickdepinguin |
last post by:
Hi,
I use zlib to write data structures to a compressed file, using the
gzwrite function. Afterwards I read the data back with gzread. I notice
that this works well when the data written is not...
|
by: lancer6238 |
last post by:
Hi,
I'm writing a program that separates a set of integers into groups and
then quicksort each group individually. However, I'm having problems
with my realloc() function. (Pardon me if the...
|
by: jacob navia |
last post by:
I am trying to compile as much code in 64 bit mode as
possible to test the 64 bit version of lcc-win.
The problem appears now that size_t is now 64 bits.
Fine. It has to be since there are...
|
by: msb_6 |
last post by:
Currently I have a PHP extension thats all written and compiles under
windows, but the PC I'm going to end up putting it on is running
Ubuntu 8.04 (g++ 4.2.3).
I've delved into PHP documentation...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |