Note that there are some explanatory texts on larger screens.

plurals
  1. PODeclaring a struct (that's already been typedef'd) within another struct?
    primarykey
    data
    text
    <p>My understanding of C is that there are two separate namespaces, one for tags (such as for structs) and one for all other variables (including structs). Using typedef before a struct definition will then treat the struct variable as a type, so if you use </p> <pre><code>struct car_part {/* Code Here */} CarPart; </code></pre> <p>(where CarPart is optional)<br> you'd have to use </p> <pre><code>struct car_part engine; </code></pre> <p>to declare a car part.<br> Whereas if you used a typedef with</p> <pre><code>typedef car_part {/* Code Here */} CarPart; </code></pre> <p>you can now use</p> <pre><code>CarPart engine; </code></pre> <p>instead.</p> <pre><code>typedef struct tag {/* Code here */} struct_name; </code></pre> <p>1) Is there any difference between declaring the actual variable before or after the block code? i.e.</p> <pre><code>typedef struct tag struct_name { /* Code here */ }; </code></pre> <p>vs</p> <pre><code>typedef struct tag { /* Code here*/ } struct_name; </code></pre> <p>2) Are there ever any advantages to not using typedef for a struct definition, even if you won't declare another struct variable of that type?</p> <p>3) The following code says that there's a syntax error C2061 with the identifier Node, but I don't see anything wrong with it. I tried adding the keyword struct before each element declaration, but that only gave more errors. Any thoughts?</p> <pre><code>typedef struct Ticket { char customer_name[20]; int ticket_number; } Ticket; typedef struct Node { Ticket ticket_info; Node *next; Node *previous; } Node; typedef struct Queue { Ticket *front; Ticket *rear; int queue_count; } Queue; </code></pre> <p>edit: fixed first two lines of code to explicitly state where the element declarations should be.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload