Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to link template header in ANSI C?
    primarykey
    data
    text
    <p>I made a template list with help of macroses. And I have an error, when I use it in more then one time in the code. There is a link error LNC2005 in MS VS. I think, it happens, because bodies of functions are in the header, is there another way to keep them?</p> <pre><code>#define GENERIC_LIST_POSTFIX i #define GENERIC_LIST_TYPE int #define GENERIC_LIST_NAME list #include "generic_list.h" #undef GENERIC_LIST_POSTFIX #undef GENERIC_LIST_TYPE #undef GENERIC_LIST_NAME </code></pre> <p>If I can't change a language, what can You advice to me? Thanks.</p> <p>There is my code</p> <pre><code>#ifndef _GENERIC_LIST_H #define _GENERIC_LIST_H #define _CAT(x,y) x##y #define CAT(x,y) _CAT(x,y) #if !defined GENERIC_LIST_POSTFIX # error("GENERIC_LIST_POSTFIX") #endif #if !defined GENERIC_LIST_TYPE # error("GENERIC_LIST_TYPE") #endif #if !defined GENERIC_LIST_NAME # error("GENERIC_LIST_NAME") #endif //------------------------------------------------------------------------------- typedef struct CAT(CAT(_list_,GENERIC_LIST_POSTFIX),_node) CAT(GENERIC_LIST_NAME,_node); struct CAT(CAT(_list_,GENERIC_LIST_POSTFIX),_node) { GENERIC_LIST_TYPE value; struct CAT(CAT(_list_,GENERIC_LIST_POSTFIX),_node) *prev; struct CAT(CAT(_list_,GENERIC_LIST_POSTFIX),_node) *next; }; //typedef struct CAT(_list_,GENERIC_LIST_POSTFIX) GENERIC_LIST_NAME; struct CAT(_list_,GENERIC_LIST_POSTFIX) { unsigned int len; // number of elements struct CAT(CAT(_list_,GENERIC_LIST_POSTFIX),_node) *first; struct CAT(CAT(_list_,GENERIC_LIST_POSTFIX),_node) *last; }; //------------------------------------------------------------------------------- void CAT(CAT(list_,GENERIC_LIST_POSTFIX),_create ) (struct CAT(_list_,GENERIC_LIST_POSTFIX) *List); { List-&gt;len = 0; List-&gt;first = NULL; List-&gt;last = NULL; } void CAT(CAT(list_,GENERIC_LIST_POSTFIX),_copy ) (struct CAT(_list_,GENERIC_LIST_POSTFIX) *scr, struct CAT(_list_,GENERIC_LIST_POSTFIX) *dest); { // ... } // ... there are more code #endif </code></pre> <p>All works, but there is another problem. I can use this .h file only one time in a one .c file. If I define GENERIC_LIST_TYPE firstly as int, than as int*, for example. </p> <pre><code>#define GENERIC_LIST_POSTFIX i #define GENERIC_LIST_TYPE int #define GENERIC_LIST_NAME list_i #include "generic_list.h" #undef GENERIC_LIST_POSTFIX #undef GENERIC_LIST_TYPE #undef GENERIC_LIST_NAME #define GENERIC_LIST_POSTFIX pi #define GENERIC_LIST_TYPE int* #define GENERIC_LIST_NAME list_pi #include "generic_list.h" #undef GENERIC_LIST_POSTFIX #undef GENERIC_LIST_TYPE #undef GENERIC_LIST_NAME </code></pre> <p>I don't get 2 lists with list_i and list_pi names. The second "list_pi" is "undeclared identifier". Is there a solution for this? Thank you twice.</p>
    singulars
    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.
    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