Reading the code of TeXmacs, I saw this:
struct texmacs_input_rep : concrete_struct {
...
};
What does that mean?
This syntax is defined in the C standard, p113, but I didn't find the meaning of it, but that's because I don't know how to read grammar rules.
Because concrete_struct
is another struct
, that contains functions looking like a constructor and a virtual destructor, and because I read elsewhere that classes in C++ are actually struct
with public members by default, I guess that this is the way of doing inheritance with struct
in C (because it is the C standard...).
Is this correct?
It is C++ syntax and equivalent to this:
class texmacs_input_rep : public concrete_struct {
public:
...
};
This is the normal syntax for inheritance of classes, here texmacs_input_rep
is inherited from concrete_struct
.
The C-Standard you linked to defines (6.7.2.1):
struct-or-union-specifier: struct-or-union identifieropt { struct-declaration-list } struct-or-union identifier struct-or-union: struct union
So according to C it must be struct
, followed by an optional identifer, followed by {
. Or only struct
followed by an identifer (a forward declaration). In neither case there is room for an additional : ...
in there.
The :
mentioned later in that paragraph of the standard is about bit-field widths, like this;
struct foo {
unsigned a : 4;
unsigned b : 3;
};
Here a
and b
are only 4 and 3 bits wide, but that's different syntax than in the question.
GCC doesn't like it (in C mode of course).
And looking at the spec, I don't see that defined at page 113 (6.7.2.1), it says :
struct-declarator:
declarator
declarator_opt : constant-expression
which is the syntax for bitfields like this :
struct blah {
int a : 4;
int b : 4;
};
So in summary: this is not C, it's C++ and it's inheritance like class inheritance.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With