Skip to content

Struct declarations must be defined before non pointer use #124

@pattersonz

Description

@pattersonz

Due to where we are placing our forward reference declarations, it's possible for structs to attempt to be used as a type within another struct before they are defined.

typedef struct X509_algor_st X509_ALGOR;
struct X509_algor_st {
    int *algorithm;
    char *parameter;
} ;
typedef struct Netscape_spki_st {
    X509_ALGOR sig_algor;
} NETSCAPE_SPKI;

The above code is a replica of what causes the error in rsa-sign. This is valid code, and is properly parsed by both superC and gcc. The output is the following:

#include <stdbool.h>
extern void __static_type_error(char *msg);
extern void __static_renaming(char *renaming, char *original);
extern void __static_condition_renaming(char *expression, char *renaming);
void __static_initializer_default();
void __static_initializer_default() {
__static_renaming("__X509_ALGOR_1", "X509_ALGOR");
__static_renaming("__NETSCAPE_SPKI_7", "NETSCAPE_SPKI");
};
typedef struct __forward_tag_reference_0  __X509_ALGOR_1;
struct __X509_algor_st_2 {
int  (* __algorithm_3);
char  (* __parameter_4);
};
struct __Netscape_spki_st_5 {
__X509_ALGOR_1  __sig_algor_6;
};
typedef struct __Netscape_spki_st_5  __NETSCAPE_SPKI_7;
struct __forward_tag_reference_0 { // generated union of struct variations                              
union {
struct __X509_algor_st_2 __X509_algor_st_2;
};
};
// typedef moved to top of scope                                                                        
struct __X509_algor_st_2 ;
// typedef moved to top of scope

this gets an error on the line
__X509_ALGOR_1 __sig_algor_6;
in the struct. Specifically it says that it is an incomplete type. The error isn't present if the field is a pointer.

This error can be fixed by moving the struct definition of __forward_tag_reference_0 to immediately after the definition of struct __X509_algor_st_2

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions