Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7592059
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T20:48:38+00:00 2026-05-30T20:48:38+00:00

I made a template list with help of macroses. And I have an error,

  • 0

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?

#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  

If I can’t change a language, what can You advice to me?
Thanks.

There is my 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->len   = 0; List->first = NULL; List->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

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.

#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 

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T20:48:39+00:00Added an answer on May 30, 2026 at 8:48 pm

    If I read your question right, you have a header like this:

    void doSomething()
    {
        printf("doing something");
    }
    

    Which causes link errors when you include the file multiple times.
    However, if you make the function static:

    static void doSomething()
    {
        printf("doing something");
    }
    

    The method will not be put to the linker, so you won’t have to worry about linker errors.

    Your other option is to put a method declaration in your header, and an implementation in a .c file elsewhere in your project.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have made a template class for a node in a linked list and
I've made some function that generates an email template. Code it generates is pure
I have made a custom suface button according this example: <Button> <Button.Template> <ControlTemplate TargetType=Button>
I have made a List of Lists implementation of a sparse matrix, and I've
I have a self made data structure (for example linked list) that works well,
I am trying to implement Koch's Snowflake. I have made a generic list, for
Recently i made two template classes,according to the book Modern C++ design. I think
I made myself a template for all JSPs in my webapp that keeps things
I made up a template to show all the fields and values from a
One of our page templates is made up of a bunch of macros. These

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.