help with this struct

L

learnfpga

I cant understand what does the 4th line do in this snippet

//struct byLightning * pPrevNode;

typedef struct byLightning
{
int data;
int nodeNum;
struct byLightning * pPrevNode;
} LIST_NODE;

Thanks for any responses....
 
R

Richard Bos

I cant understand what does the 4th line do in this snippet

//struct byLightning * pPrevNode;

typedef struct byLightning
{
int data;
int nodeNum;
struct byLightning * pPrevNode;
} LIST_NODE;

It contains the opening brace which begins the structure definition. You
probably didn't have a problem with that 4th line, so please specify
which 4th line you really meant.

Richard
 
F

Fred Kleinschmidt

I cant understand what does the 4th line do in this snippet

//struct byLightning * pPrevNode;

typedef struct byLightning
{
int data;
int nodeNum;
struct byLightning * pPrevNode;
} LIST_NODE;

Thanks for any responses....
Well, let's see. First, I'll assign line numbers, so I can figure out
what you are talking about:

1 //struct byLightning * pPrevNode;
2
3 typedef struct byLightning
4 {
5 int data;
6 int nodeNum;
7 struct byLightning * pPrevNode;
8 } LIST_NODE;

The 4th line is an opening curly brace for the stuct definition.
 
M

Mark McIntyre

I cant understand what does the 4th line do in this snippet

Which 4th line? The opening curly brace, the int nodeNum or the
structbyLightning one? [all of these are the 4th line, counting from
somewhere in your post...]
//struct byLightning * pPrevNode;

typedef struct byLightning
{
int data;
int nodeNum;
struct byLightning * pPrevNode;

this declares a pointer to the previous node in the linked list. If
you're not sure what a linked list is, you probably need to get a good
C textbook.
} LIST_NODE;

Thanks for any responses....
--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
 
N

Norbert Kolvenbach

I cant understand what does the 4th line do in this snippet

//struct byLightning * pPrevNode;

typedef struct byLightning
{
int data;
int nodeNum;
struct byLightning * pPrevNode;
} LIST_NODE;

Thanks for any responses....

Try to understand linked lists.
 
L

lovecreatesbeauty

I cant understand what does the 4th line do in this snippet

//struct byLightning * pPrevNode;

typedef struct byLightning
{
int data;
int nodeNum;
struct byLightning *pPrevNode;
} LIST_NODE;

This is a self-referral structure. The third member is a pointer to an
object of same type as the structure itself. The declaration of the
third member is ok because the base type of the pointer is known, at
that time the info of the type is enough to declare a pointer. All
pointers are the same and have the same size.
 
C

Chris Dollin

lovecreatesbeauty said:
This is a self-referral structure. The third member is a pointer to an
object of same type as the structure itself. The declaration of the
third member is ok because the base type of the pointer is known, at
that time the info of the type is enough to declare a pointer. All
pointers are the same and have the same size.

Not necessarily true.

My recollection is that all /struct/ pointers must [1] be the same size
(as a consequence of things the Standard says). But there's no
requirement that an int* and a char* are the same size, or that
a function pointer be the same size as a void* -- it could be smaller
/or bigger/.

[1] Up to "as if".
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,062
Latest member
OrderKetozenseACV

Latest Threads

Top