473,385 Members | 1,615 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Size of empty structure

1
Hi All,

I have a doubt related Size of empty structure. I know the answer of empty structure is "0".

Could Any one please let me know the reason, How and why the Result got ZERO..??
Nov 8 '14 #1
3 4486
donbock
2,426 Expert 2GB
Please show us what this empty structure looks like.
Nov 9 '14 #2
Banfa
9,065 Expert Mod 8TB
Are you talking C or C++ because the size of an empty structure in C++ is 1 and while the size of an empty structure in C is 0 there is no point in having one as it serves no purpose; it produces a warning from my compiler.
Nov 10 '14 #3
weaknessforcats
9,208 Expert Mod 8TB
In C++ you are always allowed to create a variable using the struct. That variable must exist in memory. The smallest allocation is typically one byte. Hence sizeof the struct is 1.

As far as C goes, you are required to have at least one member in a struct. If not, you get a compile error. Therefore, in C a struct does not have a size 0 because that code won't even compile.
Nov 13 '14 #4

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

Similar topics

4
by: Albert Yan Qing Ge | last post by:
typedef struct AA { } A; when use gcc compiles, sizeof(A) is 0 when use g++ compiles, sizeof(A) is 1 So I can known the length of this pointer is 1 but when I add one member to the...
6
by: MSReddy | last post by:
Hi Group, I have a structure than has other structures in it. I added 3 members to a strucuture and my program started behaving very strangly. When I printed sizes of the strucutures the values...
4
by: Abdul Samad | last post by:
banfa just said that it is because so the compiler may not assign the same memory to two variables but my question is WHY DOES COPILER ASSIGNMS MEMORY WHEN THERE IS NO NEED OF IT? as the...
4
by: Anonymous | last post by:
I need to refresh my memory on this one. If have a struct defined like this: typedef struct { char guid ; char version ; char srcId ;
2
by: arindamnitd | last post by:
How to determine the size of a structure without using the sizeof() operator
4
by: ashusharma82 | last post by:
plz check following code pMe i an structure pointer,in which char *linewisechar is made. pMe->linewisechar=(pMe->newcchar+STRLEN(pMe->newcchar)-1); here i am assigning...
1
by: sriathma | last post by:
How to Copy empty structure using Postgres. Sridharan
7
by: AnagJohari | last post by:
hello guys, Can u tell me how to find the size of structure. Please explain by giving some example. Thank you
8
Markus
by: Markus | last post by:
Hi, all. I've been doing some work with the Windows API (icky, real icky). Often times when setting the members of a structure, you have to also store the size of the structure; for example, the...
3
by: priyaagarwal | last post by:
struct st { char a; short b; char c; } what will be size of structue.
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...

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.