M
Martin Eisenberg
Hi Antoine, just redirecting you...
Martin said:Hi Antoine, just redirecting you...
Antoine said:Hi,
Is the following code legal:
------> code starts here <------
#include <stddef.h>
struct ForwardDeclared;
void foo(struct ForwardDeclared[]);
/* Dummy function, so this module contains some code. */
void dummy(void)
{
foo(NULL);
}
------> code ends here <------
?
I can see no reason why this code would not be legal, and indeed
gcc (version 3.4.5) and Microsoft C compiler (.NET) compile it
without a glitch.
Code Warrior (version 3.2.5), though, produces the following
error message:
------> CW problem starts here <------
C:\temp>mwccsym2.exe -g -O0 -inline
off -wchar_t off -align 4 -warnings on -w
nohidevirtual,nounusedexpr -msgstyle
gcc -enum int -str pool -exc ms -trigraphs on -stdinc -d _DEBUG
-d _UNICODE -d "
__SYMBIAN32__" -d "__SERIES60_30__" -d "__SERIES60_3X__" -d
"__CW32__" -d "__WIN
S__" -d "__WINSCW__" -d "WIN32" -d "_WINDOWS" -d
"__SUPPORT_CPP_EXCEPTIONS__" -c
wd source -i- -o forwardDeclaration.o -c forwardDeclaration.c
forwardDeclaration.c:5: illegal use of incomplete
struct/union/class 'struct For
wardDeclared'
Errors caused tool to abort.
------> CW problem ends here <------
Changing this line:
void foo(struct ForwardDeclared[]);
to:
void foo(struct ForwardDeclared*);
however, corrects the "problem".
So, is this (as I believe) a bug in Code Warrior (incorrectly
complains about correct code), or a bug in gcc and MS compilers
(do not detect code that is in error)?
Vladimir said:Martin said:Hi Antoine, just redirecting you...
Antoine said:Hi,
Is the following code legal:
------> code starts here <------
#include <stddef.h>
struct ForwardDeclared;
void foo(struct ForwardDeclared[]); [...]
forwardDeclaration.c:5: illegal use of incomplete
struct/union/class 'struct For
wardDeclared'
Errors caused tool to abort.
------> CW problem ends here <------
Changing this line:
void foo(struct ForwardDeclared[]);
to:
void foo(struct ForwardDeclared*);
however, corrects the "problem".
So, is this (as I believe) a bug in Code Warrior (incorrectly
complains about correct code), or a bug in gcc and MS compilers
(do not detect code that is in error)?
Well, if the code above is the *only* code in your compilation unit,
then I'm afraid the CodeWarrior is right. What you need is a proper
declaration of your `struct`. Perhaps you're missing an `#include`
containing the declaration? Arrays and pointers are not the same thing
in C (despite what some sources say).
PS
Posting full compilable example is, as always, the best policy when
asking this sort of question.
Vladimir said:Martin said:Hi Antoine, just redirecting you...
Antoine said:Hi,
Is the following code legal:
------> code starts here <------
#include <stddef.h>
struct ForwardDeclared;
void foo(struct ForwardDeclared[]);
/* Dummy function, so this module contains some code. */
void dummy(void)
{
foo(NULL);
}
------> code ends here <------
?
I can see no reason why this code would not be legal, and indeed
gcc (version 3.4.5) and Microsoft C compiler (.NET) compile it
without a glitch.
Changing this line:
void foo(struct ForwardDeclared[]);
to:
void foo(struct ForwardDeclared*);
however, corrects the "problem".
Well, if the code above is the *only* code in your compilation unit,
then I'm afraid the CodeWarrior is right. What you need is a proper
declaration of your `struct`. Perhaps you're missing an `#include`
containing the declaration? Arrays and pointers are not the same thing
in C (despite what some sources say).
PS
Posting full compilable example is, as always, the best policy when
asking this sort of question.
Kenneth said:Vladimir said:Martin said:Hi Antoine, just redirecting you...
Antoine Trux wrote:
Hi,
Is the following code legal:
------> code starts here <------
#include <stddef.h>
struct ForwardDeclared;
void foo(struct ForwardDeclared[]); [...]
forwardDeclaration.c:5: illegal use of incomplete
struct/union/class 'struct For
wardDeclared'
Errors caused tool to abort.
------> CW problem ends here <------
Changing this line:
void foo(struct ForwardDeclared[]);
to:
void foo(struct ForwardDeclared*);
however, corrects the "problem".
So, is this (as I believe) a bug in Code Warrior (incorrectly
complains about correct code), or a bug in gcc and MS compilers
(do not detect code that is in error)?
Well, if the code above is the *only* code in your compilation unit,
then I'm afraid the CodeWarrior is right. What you need is a proper
declaration of your `struct`. Perhaps you're missing an `#include`
containing the declaration? Arrays and pointers are not the same thing
in C (despite what some sources say).
But, given that a function prototype of:
void foo(struct ForwardDeclared[]);
and
void foo(struct ForwardDeclared *);
are the same thing, I don't see why CodeWarrior is complaining. You
can have pointers to incomplete types as long as you don't try to use
them for anything other than passing along elsewhere.
Or is there a difference between a function parameter declared as an
array versus a pointer?
PS
Posting full compilable example is, as always, the best policy when
asking this sort of question.
It looks like a compilable example to me. It compiles just fine on
my system, even with warnings turned up to the max.
Vladimir said:Kenneth said:Vladimir said:Martin Eisenberg wrote:
Hi Antoine, just redirecting you...
Antoine Trux wrote:
Hi,
Is the following code legal:
------> code starts here <------
#include <stddef.h>
struct ForwardDeclared;
void foo(struct ForwardDeclared[]); [...]
forwardDeclaration.c:5: illegal use of incomplete
struct/union/class 'struct For
wardDeclared'
Errors caused tool to abort.
------> CW problem ends here <------
Changing this line:
void foo(struct ForwardDeclared[]);
to:
void foo(struct ForwardDeclared*);
however, corrects the "problem".
So, is this (as I believe) a bug in Code Warrior (incorrectly
complains about correct code), or a bug in gcc and MS compilers
(do not detect code that is in error)?
Well, if the code above is the *only* code in your compilation unit,
then I'm afraid the CodeWarrior is right. What you need is a proper
declaration of your `struct`. Perhaps you're missing an `#include`
containing the declaration? Arrays and pointers are not the same thing
in C (despite what some sources say).
But, given that a function prototype of:
void foo(struct ForwardDeclared[]);
and
void foo(struct ForwardDeclared *);
are the same thing, I don't see why CodeWarrior is complaining. You
can have pointers to incomplete types as long as you don't try to use
them for anything other than passing along elsewhere.
Or is there a difference between a function parameter declared as an
array versus a pointer?
Hmmm. I may have messed this one up.
The only *warning* I get is:
main.c:3: warning: array type has incomplete element type
Which I don't think is required by the standard.
Hi Antoine, just redirecting you...
Antoine said:Hi,
Is the following code legal:
------> code starts here <------
#include <stddef.h>
struct ForwardDeclared;
void foo(struct ForwardDeclared[]);
/* Dummy function, so this module contains some code. */
void dummy(void)
{
foo(NULL);
}
------> code ends here <------
?
I can see no reason why this code would not be legal, and indeed
gcc (version 3.4.5) and Microsoft C compiler (.NET) compile it
without a glitch.
Code Warrior (version 3.2.5), though, produces the following
error message:
------> CW problem starts here <------
C:\temp>mwccsym2.exe -g -O0 -inline
off -wchar_t off -align 4 -warnings on -w
nohidevirtual,nounusedexpr -msgstyle
gcc -enum int -str pool -exc ms -trigraphs on -stdinc -d _DEBUG
-d _UNICODE -d "
__SYMBIAN32__" -d "__SERIES60_30__" -d "__SERIES60_3X__" -d
"__CW32__" -d "__WIN
S__" -d "__WINSCW__" -d "WIN32" -d "_WINDOWS" -d
"__SUPPORT_CPP_EXCEPTIONS__" -c
wd source -i- -o forwardDeclaration.o -c forwardDeclaration.c
forwardDeclaration.c:5: illegal use of incomplete
struct/union/class 'struct For
wardDeclared'
Errors caused tool to abort.
------> CW problem ends here <------
Changing this line:
void foo(struct ForwardDeclared[]);
to:
void foo(struct ForwardDeclared*);
however, corrects the "problem".
So, is this (as I believe) a bug in Code Warrior (incorrectly
complains about correct code), or a bug in gcc and MS compilers
(do not detect code that is in error)?
Antoine Trux
name []" is exactly equivalent to "type *name", with the exception of
a special case for compilers conforming to the 1999 or later version
of the C standard, and that special case does not apply here.
Jack Klein said:Hi Antoine, just redirecting you...
Antoine said:Hi,
Is the following code legal:
------> code starts here <------
#include <stddef.h>
struct ForwardDeclared;
void foo(struct ForwardDeclared[]);
/* Dummy function, so this module contains some code. */
void dummy(void)
{
foo(NULL);
}
------> code ends here <------
?
I can see no reason why this code would not be legal, and indeed
gcc (version 3.4.5) and Microsoft C compiler (.NET) compile it
without a glitch.
Code Warrior (version 3.2.5), though, produces the following
error message:
------> CW problem starts here <------
C:\temp>mwccsym2.exe -g -O0 -inline
off -wchar_t off -align 4 -warnings on -w
nohidevirtual,nounusedexpr -msgstyle
gcc -enum int -str pool -exc ms -trigraphs on -stdinc -d _DEBUG
-d _UNICODE -d "
__SYMBIAN32__" -d "__SERIES60_30__" -d "__SERIES60_3X__" -d
"__CW32__" -d "__WIN
S__" -d "__WINSCW__" -d "WIN32" -d "_WINDOWS" -d
"__SUPPORT_CPP_EXCEPTIONS__" -c
wd source -i- -o forwardDeclaration.o -c forwardDeclaration.c
forwardDeclaration.c:5: illegal use of incomplete
struct/union/class 'struct For
wardDeclared'
Errors caused tool to abort.
------> CW problem ends here <------
Changing this line:
void foo(struct ForwardDeclared[]);
to:
void foo(struct ForwardDeclared*);
however, corrects the "problem".
So, is this (as I believe) a bug in Code Warrior (incorrectly
complains about correct code), or a bug in gcc and MS compilers
(do not detect code that is in error)?
Antoine Trux
Absolutely a bug in Code Warrior. In function declarations, "type
name []" is exactly equivalent to "type *name", with the exception of
a special case for compilers conforming to the 1999 or later version
of the C standard, and that special case does not apply here.
So I would suggest submitting a bug report to Metrowerks.
But I would also suggest using "struct ForwardDeclared*", both to get
on with your work immediately, and because I don't like the [] syntax
in declarations because it misleads newbies, and obviously at least
one compiler's parser.
Flash said:Not when the problem is that it won't compile as in this case! That's a
bit like saying to someone they should not go to the doctor for advice
until they have recovered from whatever they are suffering from!
Absolutely a bug in Code Warrior. In function declarations, "type
name []" is exactly equivalent to "type *name", with the exception of
a special case for compilers conforming to the 1999 or later version
of the C standard, and that special case does not apply here.
Then, how do you interpret the following paragraph from the C99 Standard
(thanks to Harald van Dijk for pointing it out):
------> start of C99 Standard excerpt <------
6.7.5.2 Array declarators
Constraints
1 In addition to optional type qualifiers and the keyword static, the [
and ] may delimit
an expression or *. If they delimit an expression (which specifies the size
of an array), the
expression shall have an integer type. If the expression is a constant
expression, it shall
have a value greater than zero. The element type shall not be an incomplete
or function
type. The optional type qualifiers and the keyword static shall appear only
in a
declaration of a function parameter with an array type, and then only in the
outermost
array type derivation.
------> end of C99 Standard excerpt <------
?
Antoine
Jack said:Absolutely a bug in Code Warrior. In function declarations, "type
name []" is exactly equivalent to "type *name", with the exception of
a special case for compilers conforming to the 1999 or later version
of the C standard, and that special case does not apply here.
Then, how do you interpret the following paragraph from the C99 Standard
(thanks to Harald van Dijk for pointing it out):
------> start of C99 Standard excerpt <------
6.7.5.2 Array declarators
Constraints
1 In addition to optional type qualifiers and the keyword static, the [
and ] may delimit
an expression or *. If they delimit an expression (which specifies the size
of an array), the
expression shall have an integer type. If the expression is a constant
expression, it shall
have a value greater than zero. The element type shall not be an incomplete
or function
type. The optional type qualifiers and the keyword static shall appear only
in a
declaration of a function parameter with an array type, and then only in the
outermost
array type derivation.
------> end of C99 Standard excerpt <------
?
Antoine
The issue is not how I interpret this clause of the C standard, but
rather how I determine that this clause does not apply. In the
parameter section of a function declarator, this is _not_ an array
declarator.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.