This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

struct problem / usart

I'm working with the RealView Compiler and have a strange problem with the usart.

I've installed one typedef struct in a headerfile - when I try to install a array of this struct in the c-file (as global struct variable) - I'm not able to get some printf() messages over the usart (no data abort or anything else (the program seems to work) - only no messages over the usart..

When I install the array of this struct in a function within this c-file (not global) - everything works ok...

Could there be a problem with less stack size?

tobi

Parents
  • at the moment I have one headerfile where all other headerfiles where included - so in every c-file I only include this headerfile...

    If I use in one of this heatherfiles to define my struct -> then I have to use extern to define a variable, haven't I? So that could be the reason for my strange errors?

    header.h
    
    #include header1.h
    #include header2.h
    
    header1.h
    
    typedef struct {...}STRUCT_VAR;
    extern STRUCT_VAR struct_array[];
    
    header1.c
    
    #include <header.h>
    STRUCT_VAR struct_array[NBR_STRUCT];
    

    BTW, is this a common way? Or is it better to have in every c-file all #include <header.h> which are needed in the specific c-file?

Reply
  • at the moment I have one headerfile where all other headerfiles where included - so in every c-file I only include this headerfile...

    If I use in one of this heatherfiles to define my struct -> then I have to use extern to define a variable, haven't I? So that could be the reason for my strange errors?

    header.h
    
    #include header1.h
    #include header2.h
    
    header1.h
    
    typedef struct {...}STRUCT_VAR;
    extern STRUCT_VAR struct_array[];
    
    header1.c
    
    #include <header.h>
    STRUCT_VAR struct_array[NBR_STRUCT];
    

    BTW, is this a common way? Or is it better to have in every c-file all #include <header.h> which are needed in the specific c-file?

Children
No data