Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><strong>1)</strong> The difference between those two blocks of code is that the first one is invalid syntax, while the second one is good and useful. I use the second one in order to define a struct and also define a typedef for the struct at the same time. My code has stuff that looks like this:</p> <pre><code>typedef struct Dog { int age, barks; } Dog; </code></pre> <p>After that line, I can define dogs with <code>Dog mydog;</code> or <code>struct Dog mydog;</code>.</p> <p>It's important to understand that the code above is doing two things. It is defining a type named <code>struct Dog</code>, and then it is defining a type named <code>Dog</code> that just refers to <code>struct Dog</code>. You could split that into two separate steps like this:</p> <pre><code>struct Dog { int age, barks; }; typedef struct Dog Dog; </code></pre> <p><strong>2)</strong> I always use the typedef as shown above in the first block of code and have found no problem with it. I would say there are no advantages to leaving out the typdef. Just for the record, if you want to leave out the typedef and only define a struct, then you code would be:</p> <pre><code>struct Dog { int age, barks; }; </code></pre> <p>If you do it that way, you can only make new dogs by typing <code>struct Dog mydog;</code>; in other words, the name of the type is only <code>struct Dog</code> and <code>Dog</code> does not name a type.</p> <p><strong>3)</strong> The problem is that you are trying to use "Node" inside the definition of "Node". That would be a circular definition. You can fix everything by just writing it like this:</p> <pre><code>struct Node; typedef struct Node { struct Node * next; struct Node * previous; } Node; </code></pre>
 

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