473,513 Members | 2,749 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Size of Struct variable of size zero

2 New Member
Assalam mu Alikum,

i understand the size of structure with no data types is zero. but why the size of structure variable is 1 Byte when the size of that structure is zeor?

for example

struct student{
} st;

here structure student has zero size but why the size of st is not zero? why it is one?

plz reply soon as i am having assignemtn concerned to this topic
regards
Apr 4 '07 #1
1 2043
Banfa
9,065 Recognized Expert Moderator Expert
The C++ standard forbids any 2 variables having the same address in memory. The easiest way to do this is for all variables to have a size then they can not occupy the same location in memory.

A structure (or class) with no members would nominally have 0 size, however this breaks the stipulation above that all variables must have a size != 0 so that they do not occupy the same address in memory so the compiler assigns a stucture with no members a dummy size of 1 in order to meet the requirements of the specification.
Apr 4 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

25
2661
by: prashna | last post by:
Hi all, I have seen a piece of code(while doing code review) which declared an array of size 0.One of my friend told although it is not standard C,some compilers will support this..I am very...
5
5579
by: nmtoan | last post by:
Hi, I could not find any answer to this simple question of mine. Suppose I have to write a program, the main parts of it are as follows: #include <blahblah.h> struct {
2
1331
by: Mockey Chen | last post by:
I saw some library code wrote like this: struct X{ int x; char y; /* Note: here array size is ZERO, why? */ }; Why use array size zero. I heard about the C standard not allow array...
8
10145
by: redefined.horizons | last post by:
I would like to have an array declaration where the size of the array is dependent on a variable. Something like this: /* Store the desired size of the array in a variable named "array_size". */...
15
2839
by: chandanlinster | last post by:
Consider the following program fragment: /************************/ struct some_struct { }a; printf("%d", sizeof(a)); /*************************/
74
15870
by: Zytan | last post by:
I have a struct constructor to initialize all of my private (or public readonly) fields. There still exists the default constructor that sets them all to zero. Is there a way to remove the...
0
6519
by: shrik | last post by:
I have following error : Total giant files in replay configuration file are : File name : /new_file/prob1.rec Given file /new_file/prob1.rec is successfully verified. Splitting for giant file...
36
3762
by: James Harris | last post by:
Initial issue: read in an arbitrary-length piece of text. Perceived issue: handle variable-length data The code below is a suggestion for implementing a variable length buffer that could be used...
11
1721
by: sinbad | last post by:
chip_init.c 1 #include <stdio.h> 2 struct a { 3 char buf; 4 }b; 5 struct c { 6 char buf; 7 }d; 8
0
7380
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7535
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7523
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5085
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
4745
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3232
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3221
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
798
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
455
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.