L
Luca Forlizzi
Hello,
while studying incomplete types, I wrote the below example
containing, I think,
several undef. behaviors. Trying it with two different compilers I
find out
that expressions that, in my opinion, are all undef. b. for the same
reason,
produce non uniform translations (I used -std=c99 -pedantic-errors -
Wall for gcc).
I have the following questions:
1)Am I right that all the 8 expressions casted to void are undef.b.
per 6.3.2.1 p.2
2) gcc prints "error: dereferencing pointer to incomplete type"
while trying
to translate
(void) *ps;
Does the standard forbids to dereference a pointer to an
incomplete type?
I was unable to find such a prohibition, moreover gcc silently
accepts
dereferencing a pointer to an incomplete array type. In my
opinion the
error message is misleading regading the nature of the error.
/*------------------ EXAMPLE --------------------*/
/* declaration of an external variabile of incomplete type; later
type is completed and variable defined */
struct S external_s;
/* tentative definition of a variable with incomplete type;
later type is completed and the tentative def becomes a definition
(the variable is implicitly initialized to {0}) */
struct S tentative_s;
int main(void) {
/* pointers to the incomplete structure type */
struct S *ps, *qs;
/* declaration of functions returning an incomplete structure type */
struct S hht(void);
struct S hhe(void);
ps = &tentative_s;
qs = &external_s;
/* all following statements are (discarded) computation of an
expression
having an incomplete structure type.
Are they all undef.b. per 6.3.2.1 p.2 ?
*/
/* gcc emits diagnostics, vbcc silently accepts them */
(void) hht();
(void) hhe();
/* both gcc and vbcc emit diagnostics */
(void) *ps;
(void) *qs;
/* gcc silently accepts them, vbcc emits diagnostics */
(void) * &tentative_s;
(void) * &external_s;
/* both gcc and vbcc silently accept them */
(void) tentative_s;
(void) external_s;
return 0;
}
/* declaration that completes the structure type and defines
external_s */
struct S { float a; int b, c; } external_s = { 1.1, 2, 3, };
/* functions returning the here-complete structure type */
struct S hht(void) {
return tentative_s;
}
struct S hhe(void) {
return external_s;
}
while studying incomplete types, I wrote the below example
containing, I think,
several undef. behaviors. Trying it with two different compilers I
find out
that expressions that, in my opinion, are all undef. b. for the same
reason,
produce non uniform translations (I used -std=c99 -pedantic-errors -
Wall for gcc).
I have the following questions:
1)Am I right that all the 8 expressions casted to void are undef.b.
per 6.3.2.1 p.2
2) gcc prints "error: dereferencing pointer to incomplete type"
while trying
to translate
(void) *ps;
Does the standard forbids to dereference a pointer to an
incomplete type?
I was unable to find such a prohibition, moreover gcc silently
accepts
dereferencing a pointer to an incomplete array type. In my
opinion the
error message is misleading regading the nature of the error.
/*------------------ EXAMPLE --------------------*/
/* declaration of an external variabile of incomplete type; later
type is completed and variable defined */
struct S external_s;
/* tentative definition of a variable with incomplete type;
later type is completed and the tentative def becomes a definition
(the variable is implicitly initialized to {0}) */
struct S tentative_s;
int main(void) {
/* pointers to the incomplete structure type */
struct S *ps, *qs;
/* declaration of functions returning an incomplete structure type */
struct S hht(void);
struct S hhe(void);
ps = &tentative_s;
qs = &external_s;
/* all following statements are (discarded) computation of an
expression
having an incomplete structure type.
Are they all undef.b. per 6.3.2.1 p.2 ?
*/
/* gcc emits diagnostics, vbcc silently accepts them */
(void) hht();
(void) hhe();
/* both gcc and vbcc emit diagnostics */
(void) *ps;
(void) *qs;
/* gcc silently accepts them, vbcc emits diagnostics */
(void) * &tentative_s;
(void) * &external_s;
/* both gcc and vbcc silently accept them */
(void) tentative_s;
(void) external_s;
return 0;
}
/* declaration that completes the structure type and defines
external_s */
struct S { float a; int b, c; } external_s = { 1.1, 2, 3, };
/* functions returning the here-complete structure type */
struct S hht(void) {
return tentative_s;
}
struct S hhe(void) {
return external_s;
}