•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C section within the Software Development category of DaniWeb, a massive community of 427,488 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,418 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C advertiser: Programming Forums
Views: 2405 | Replies: 3
![]() |
•
•
Join Date: Aug 2006
Posts: 29
Reputation:
Rep Power: 3
Solved Threads: 1
C--Structures(inside structure declaration of variable of same type is not allowed)
#1
Sep 6th, 2006
It is not allowed to declare a variable of same structure type but it is allowed to declare a pointer. For example,
My question is when we can declare a pointer of same type why not a variable of same type.
I will be exremely grateful if somebody answers my question.
Thanks
Iqbal
struct node {
int a;
struct node x; //not allowed
struct node *pnext; //allowed
};My question is when we can declare a pointer of same type why not a variable of same type.
I will be exremely grateful if somebody answers my question.
Thanks
Iqbal
Last edited by WolfPack : Sep 6th, 2006 at 5:02 am. Reason: Moved the question to outside code tags.
•
•
Join Date: Jun 2005
Location: Tokyo, Japan
Posts: 1,481
Reputation:
Rep Power: 8
Solved Threads: 102
Re: C--Structures(inside structure declaration of variable of same type is not allowed)
#2
Sep 6th, 2006
Re: C--Structures(inside structure declaration of variable of same type is not allowe
#3
Sep 6th, 2006
You've basically written this
You can't infinitely expand copies of yourself when declaring a structure.
The way the cycle is broken is by having a pointer, which is always a fixed size regardless of the amount of data being pointed at.
struct node {
int a;
struct node {
int a;
struct node {
int a;
struct node {
int a;
struct node {
int a;
struct node x; // and so on....
struct node *pnext;
}x;
struct node *pnext;
}x;
struct node *pnext;
}x;
struct node *pnext;
}x;
struct node *pnext;
};The way the cycle is broken is by having a pointer, which is always a fixed size regardless of the amount of data being pointed at.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
Do not PM me for help; You'll be ignored, or told to learn to read.
Do not ask me if I'm muslim - I'm not. Nor do I care about yours or anyone else's mysticism. Religion is a matrix, take the RED PILL.
Do not PM me for help; You'll be ignored, or told to learn to read.
Do not ask me if I'm muslim - I'm not. Nor do I care about yours or anyone else's mysticism. Religion is a matrix, take the RED PILL.
•
•
Join Date: Aug 2006
Posts: 29
Reputation:
Rep Power: 3
Solved Threads: 1
Re: C--Structures(inside structure declaration of variable of same type is not allowe
#4
Sep 7th, 2006
![]() |
•
•
•
•
•
•
•
•
DaniWeb C Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- structure bit fields (C)
- how to cast a string type variable to LPCTSTR type (C++)
- Program alone doesn't help. (C++)
- Why does my array still empty (C++)
- Structure Help Please (C++)
- accessing private data members (C++)
Other Threads in the C Forum
- Previous Thread: how to generate a state transition diagram in c
- Next Thread: grade prediction program



Linear Mode