This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

How make shared struct using #pragma DATA_SECTION



Hi, i need make shared 'struct stack' using #pragma DATA_SECTION, how can i make it?

struct stack {
  int elmt[MAX];
  int head;
};

Tnx to answer.

  • I'm not sure what you mean by a shared struct.  Do you mean you need multiple source files to know the members in a "struct stack"?  You do that by putting the definition of "struct stack" in a header file, then including that header file in C source files with the preprocessor directive #include.  The DATA_SECTION pragma has no role in any of that.  The DATA_SECTION pragma is not applied to the type struct stack, but to variables of that type.  Suppose struct strack is defined in a header file named struct_defs.h.  Then a C source file could have lines like this ...

    #include "struct_defs.h"
    #pragma DATA_SECTION(global_stack, "section_name_here");
    struct stack global_stack;

    Thanks and regards,

    -George