3
Contributors
2
Replies
3
Views
10 Years
Discussion Span
Last Post by Narue
0

Its posible to do that, but in most of the cases you use it, it will fail. For instance, try to compile this and see the results:

#include <stdio.h>

struct
{
    char * name;
    int age;   
};

struct
{
    long artNum;
    float pr;
};

int
main( void )
{
    struct person;
    struct article;
    
    person.name = NULL;
    
    article.pr = 123.32
    
    return 0;
}

I recommend you, not to do this. In fact, its a good programming practice to define new types with typedef, when you want to define a struct. If not, always tag them. Like this,

typedef struct person
{
    char * name;
    int age;   
} personT;

/* or */

struct art
{
    long artNum;
    float pr;
};

Good Luck!

0

It's best to always tag your structures, even if you typedef them:

typedef struct mystruct {
  /* Members */
} mystruct;

or

struct mystruct {
  /* Members */
};
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.