Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

F: struct declaration #51

Open
Konstantin8105 opened this issue Apr 5, 2018 · 2 comments
Open

F: struct declaration #51

Konstantin8105 opened this issue Apr 5, 2018 · 2 comments

Comments

@Konstantin8105
Copy link
Owner

struct s* p = NULL; // tag naming an unknown struct declares it
struct s { int a; }; // definition for the struct pointed to by p
void g(void)
{
    struct s; // forward declaration of a new, local struct s
              // this hides global struct s until the end of this block
    struct s *p;  // pointer to local struct s
                  // without the forward declaration above,
                  // this would point at the file-scope s
    struct s { char* p; }; // definitions of the local struct s
}

see http://en.cppreference.com/w/c/language/struct

@Konstantin8105
Copy link
Owner Author

struct y;
struct x { struct y *p; /* ... */ };
struct y { struct x *q; /* ... */ };

int vv(){
struct y;
struct x2 { struct y *p2; /* ... */ };
struct y { struct x2 *q; /* ... */ };
}

@Konstantin8105
Copy link
Owner Author

Konstantin8105 commented Apr 5, 2018

// Link: http://en.cppreference.com/w/c/language/struct
struct yS;
struct x  { struct yS *p;  int ax;};
struct yS { struct x  *q;  int ay;};

int test_vv(){
       struct yS var_y;
       struct x  var_x;
       var_x.p = &var_y;
       var_x.ax = 10;
       var_y.q = &var_x;
       var_y.ay = 42;
       is_eq(var_x.ax , 10);
       is_eq((*var_x.p).ay , 42);
       
       struct yS;
       struct x2  { struct yS *p2; float bx2; };
       struct yS  { struct x2  *q; float by ; };

       struct yS var_y2;
       struct x2 var_x2;
       var_x2.p2 = &var_y2;
       var_x2.bx2 = 100;
       var_y2.q = &var_x2;
       var_y2.by = 420;
       is_eq(var_x2.bx2 , 100);
       is_eq((*var_x2.p2).by , 420);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant