我有以下代码片段,我想知道它是纯 C 还是包含一些 C++ 元素。这个问题源于我认为它只是C,但是一些编译器不接受代码。
// User struct derived from FunctionBlock
struct Function{
// Inputs
int codeGenerationIterator;
int i;
char* s;
// Outputs
// Internal
};
void FunctionCall(struct Function *arg){
}
void FunctionConstructor(struct Function *arg){
arg->i=3;
arg->s="!";
// Call constructor for all not primitive variables
// Create struct with first call
FunctionCall(arg);
}
// User type definition
typedef struct Punto{
int codeGenerationIterator;
Function x[3+1];
Function *x_pointer[3+1];
double y;
};
void PuntoConstructor(struct Punto *arg){
// Call constructor for all not primitive variables
for(arg->codeGenerationIterator=0;arg->codeGenerationIterator<=3;arg->codeGenerationIterator++){
arg->x_pointer[arg->codeGenerationIterator]=&(arg->x[arg->codeGenerationIterator]);
FunctionConstructor(arg->x_pointer[arg->codeGenerationIterator]);
}
}
// User type definition
typedef struct Cerchio{
int codeGenerationIterator;
double r;
Punto centro;
Punto *centro_pointer;
};
void CerchioConstructor(struct Cerchio *arg){
// Call constructor for all not primitive variables
arg->centro_pointer=&(arg->centro);
PuntoConstructor(arg->centro_pointer);
}
// User type definition
typedef struct Container{
int codeGenerationIterator;
Cerchio circonferenza[10+1];
Cerchio *circonferenza_pointer[10+1];
};
void ContainerConstructor(struct Container *arg){
// Call constructor for all not primitive variables
for(arg->codeGenerationIterator=0;arg->codeGenerationIterator<=10;arg->codeGenerationIterator++){
arg->circonferenza_pointer[arg->codeGenerationIterator]=&(arg->circonferenza[arg->codeGenerationIterator]);
CerchioConstructor(arg->circonferenza_pointer[arg->codeGenerationIterator]);
}
}
int main(void){
// Variable definitions
int codeGenerationIterator;
int count;
Punto insiemePunti[50+1];
Punto *insiemePunti_pointer[50+1];
Cerchio cerchio;
Cerchio *cerchio_pointer;
Container container;
Container *container_pointer;
Container containers[11+1];
Container *containers_pointer[11+1];
// Call constructor for all not primitive variables
for(codeGenerationIterator=0;codeGenerationIterator<=50;codeGenerationIterator++){
insiemePunti_pointer[codeGenerationIterator]=&insiemePunti[codeGenerationIterator];
PuntoConstructor(insiemePunti_pointer[codeGenerationIterator]);
}
cerchio_pointer=&cerchio;
CerchioConstructor(cerchio_pointer);
container_pointer=&container;
ContainerConstructor(container_pointer);
for(codeGenerationIterator=0;codeGenerationIterator<=11;codeGenerationIterator++){
containers_pointer[codeGenerationIterator]=&containers[codeGenerationIterator];
ContainerConstructor(containers_pointer[codeGenerationIterator]);
}
container.circonferenza[1].centro.x[0].i=2;
containers[2].circonferenza[2].centro.x[4].i=2;
printf("Works!");
getchar();getchar(); // TODO: delete
return 0;
}
如您所见,我没有使用类或重载,而只使用了简单的指令、结构和一些指针。那么,为什么一些严格的 C 编译器会给我一个错误?