Anonymous Struct Pointer [closed]

No, the sample code is not valid syntax. A compiling attempt will show that.

Re-writing into what it appears you are asking is the following example, you ask “how does one reference the (anonymous struct) pointer later in the program?”

int random_function(int random_variable) {
  // Supposed Anonymous Struct Pointer, but invalid syntax.
  struct struct_name *;  
}

It appears you are mixing what is anonymous. Your example hints that you think the structure has a name and the variable is anonymous, which if could happen would make it inaccessible.

A correct example of Anonymous Struct Pointer would be

int random_function(int random_variable) {
  struct /* no structure tag here */ {
    int a;
    int b;
  } *variable_name;
  variable_name = malloc(sizeof *variable_name);
  variable_name->a = 1;
  variable_name->a = 2;
  return variable_name->a;
}

Here you can see the structure has no tag, that makes it an anonymous structure. variable_name becomes a pointer to an anonymous structure . The variable is accessed in the usual ways.

Leave a Comment