Home > Back-end >  Statement of C data types, but don't understand, please advise!
Statement of C data types, but don't understand, please advise!

Time:11-10

CodePudding user response:

Under the missed # define _LIST_H
This is to prevent repeated error caused by the repeated contains, add a.c contains a.h b.h, contain and a.h b.h, so in a.c, b.h contained twice, using the macro definition, the second, because of the macro definition and make the # if # endif blocks

CodePudding user response:

reference 1st floor SuperDay response:
under the missed # define _LIST_H
This is to prevent repeated error caused by the repeated contains, add a.c contains a.h b.h, contain and a.h b.h, so in a.c, b.h contained twice, using the macro definition, the second, because of the macro definition and make the # if # endif blocks failure

This I know, I want to ask variable definitions of how to return a responsibility, pseudo code?

CodePudding user response:

refer to the second floor qq_41842671 response:
Quote: refer to 1st floor SuperDay response:
under the missed # define _LIST_H
This is to prevent repeated error caused by the repeated contains, add a.c contains a.h b.h, contain and a.h b.h, so in a.c, b.h contained twice, using the macro definition, the second, because of the macro definition and make the # if # endif blocks failure

This I know, I want to ask variable definitions of how to return a responsibility, pseudo code?


For the meaning of pseudo code, I'm afraid you have misunderstood, pseudo code mean, use a code to express an algorithm or process, and this code is generally does not exist in reality, you provide the code is the C language, clearly shows a way of implementation, it wouldn't be pseudo code,

Again, to distinguish declarations and definitions, the statement is announced the existence of a type, in general, which does not reflect the details, like you here "struct Node;" , it is a kind of statement, the inside of the struct members did not show up here, when we just use Pointers or references, this detail is not necessary, the benefits of this approach is to hide details, accord with the spirit of OOP,
And definition is specific types of content part (as for a struct or class member), and define only in one place, so repeated contains will go wrong, when you are quoting the definition, similar to the new operation can, because the new operation need to know the need to assign for instance how much memory space, and if it is to declare, is not new,

For typedef, you can define it became a synonym for understanding, like "typedef a, b." So b is a synonym, but this must be a declaration or definition, in the code above, the first statement "struct Node;" And then "typedef struct Node * PtrToNode;" PtrToNode ", that is to say, "is" typedef struct Node * "synonyms,
Beginners is easy to confuse this format, for example, when you declare a function of time, usually goes like this:
Int fun (int, const char *);
How should the function (pointer) types of synonyms defined? How to see this structure? Look at the following formula:
Typedef int (* funptr) (int, const char *);
Like this, in the form of a kind of the trick is to find an identifier, this formula is funptr inside, and then the content of the inside of the parentheses to restore with fun, so you back to the above the function declaration:
Int fun (int, const char *);
Funptr and fun belong to the same type, then can proceed to the assignment, "funptr=fun;" , so after, can use funptr instead of fun executive functions, such as: int res=funptr (100, "China");

CodePudding user response:

I'm sorry, just now code word is more, the last part of writing has a problem, I correct once again,

To distinguish declarations and definitions, the statement is announced the existence of a type, in general, which does not reflect the details, like you here "struct Node;" , it is a kind of statement, the inside of the struct members did not show up here, when we just use Pointers or references, this detail is not necessary, the benefits of this approach is to hide details, accord with the spirit of OOP,
And definition is specific types of content part (as for a struct or class member), and define only in one place, so repeated contains will go wrong, when you are quoting the definition, similar to the new operation can, because the new operation need to know the need to assign for instance how much memory space, and if it is to declare, is not new,

For typedef, you can define it became a synonym for understanding, like "typedef a, b." So b is a synonym, but this must be a declaration or definition, in the code above, the first statement "struct Node;" And then "typedef struct Node * PtrToNode;" PtrToNode ", that is to say, "is" typedef struct Node * "synonyms,
Beginners is easy to confuse this format, for example, when you declare a function of time, usually goes like this:
Int fun (int, const char *);
How should the function (pointer) types of synonyms defined? How to see this structure? Look at the following formula:
Typedef int (* funptr) (int, const char *);
Like this, in the form of a kind of the trick is to find an identifier, this formula is funptr inside, and then the content of the inside of the parentheses to restore with fun, so you back to the above the function declaration:
Int fun (int, const char *);
Funptr and fun belong to the same type, then can proceed to the assignment, "funptr f1=fun;" , so after, can replace fun with f1 to perform functions, such as: int res=f1 (100, "China");

In addition, "funptr f1;" With the following written equivalent, when more concise:
Int (*) f1 (int, const char *);
  • Related