473,403 Members | 2,270 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,403 software developers and data experts.

empty structure in C

4
Can a blank struct b declared
· Can an array of blank struct b declared
· If yes what does a[3] point to
Jul 3 '14 #1
4 1619
weaknessforcats
9,208 Expert Mod 8TB
Have you tried this?

When you declare a struct, this is valid:

struct data
{
};

Expand|Select|Wrap|Line Numbers
  1. int main()
  2. {
  3.    struct data var;
  4.  
  5.    struct data* ptr = &var;
  6. }
That is, you are allowed to define a pointer to a struct object. This requires that there be a struct object so you can put its address in the pointer. This, in turn, requires that there be a struct object of at least one byte so you can get the address.
Jul 3 '14 #2
It points to first address of the array.
Jul 3 '14 #3
weaknessforcats
9,208 Expert Mod 8TB
It's better to say the pointer contains "the address of element 0".

Also, a[3] is not a pointer. It is really the element at the location of "the address of element 0 plus 3 times the sizeof the struct." That would be the 4th element of the array.
Jul 3 '14 #4
donbock
2,426 Expert 2GB
A struct or union declaration that does not identify any internal fields is an incomplete type. The compiler knows the name of the incomplete type, but it does not know the size of the incomplete type; thus, you cannot declare variables of that type (including arrays of that type) nor can an incomplete type be passed to sizeof. You can, however, declare pointers to an incomplete type. Declaration of an incomplete type is frequently followed by a redeclaration of that type that identifies the internal fields. This completes the type.

What good is an incomplete type?

It is helpful for declaring linked lists. The following snippet could not declare the link without the incomplete type declaration.
Expand|Select|Wrap|Line Numbers
  1. struct node;
  2. struct node { struct node *link; int payload };
It is helpful for information hiding. Users of a service include the public header and then call the public functions. The implementation of the service includes the private header. This leaves users of the service unable to access individual fields of the structure.
Expand|Select|Wrap|Line Numbers
  1. Public header...
  2. struct myhandle;
  3. struct myhandle *getNewThing(void);
  4. int changeThing(struct myhandle *);
  5.  
  6. Private header...
  7. #include "public header"
  8. struct myhandle {
  9.     ...
  10.     };
Jul 3 '14 #5

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

Similar topics

23
by: Mikko Ohtamaa | last post by:
From XML specification: The representation of an empty element is either a start-tag immediately followed by an end-tag, or an empty-element tag. (This means that <foo></foo> is equal to...
4
by: shane | last post by:
From searching around, Ive seen this question asked numerous times, but havent seen a usable answer unfortuantly. What Im trying to do is something I would have thought would be quite common,...
1
by: deko | last post by:
DoCmd.CopyObject copies data, but I only need structure. I'm trying to clone several tables in my Access 2003 mdb. The goal is to link to a series of Excel spreadsheets and then run various...
26
by: Michel Rouzic | last post by:
I have a binary file used to store the values of variables in order to use them again. I easily know whether the file exists or not, but the problem is, in case the program has been earlier...
10
by: Duncan M Gunn | last post by:
Hi, I need to store the following matrix of values: T U V A 2 1 1 B 2 - - C - - 2 Where (-) is an empty cell.
22
by: EMW | last post by:
Hi, I managed to create a SQL server database and a table in it. The table is empty and that brings me to my next chalenge: How can I get the info in the table in the dataset to go in an empty...
6
by: zulander | last post by:
Hi i have a Public Structure: Public Structure MeterAccountName Dim Meter As String Dim Account_No As String Dim xName As String End Structure is their a way to clear a structure without...
1
by: chpushpakumar | last post by:
Why An Empty Structure will occupy 2bytes of memory in C++
2
by: Phoenix | last post by:
Hi Friends , Could anyone please help me to resolve the following issue : I pass an array of structures to a dll written in VC++ 6.0 whih fills it with data . The following works well for VB...
1
by: sriathma | last post by:
How to Copy empty structure using Postgres. Sridharan
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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,...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.