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[]); /* 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>mwccsym 2.exe -g -O0 -inline off -wchar_t off -align 4 -warnings on -w nohidevirtual,n ounusedexpr -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 forwardDeclarat ion.o -c forwardDeclarat ion.c forwardDeclarat ion.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 11 2594
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[]); /* 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>mwccsym 2.exe -g -O0 -inline off -wchar_t off -align 4 -warnings on -w nohidevirtual,n ounusedexpr -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 forwardDeclarat ion.o -c forwardDeclarat ion.c forwardDeclarat ion.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 Oka wrote: 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[]);
[...] forwardDeclarat ion.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.
--
+-------------------------+--------------------+-----------------------------+
| Kenneth J. Brody | www.hvcomputer.com | |
| kenbrody/at\spamcop.net | www.fptech.com | #include <std_disclaimer .h> |
+-------------------------+--------------------+-----------------------------+
Don't e-mail me at: <mailto:Th***** ********@gmail. com>
Kenneth Brody wrote: Vladimir Oka wrote: 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[]); [...] > forwardDeclarat ion.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.
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.
I think you're right, and I was wrong.
Unfortunately, I don't have time at the moment to dig deeper into it
(train timetables don't care about C), but I'm sure someone will.
PS
I still think parameter declaration should have used pointers instead
of arrays, though. A matter of style, I know, but...
Vladimir Oka wrote: 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[]); /* 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.
Try harder with gcc and you might get it to generate a warning.
markg@markgordo n-lp ~
$ cat t.c
#include <stddef.h>
struct ForwardDeclared ;
void foo(struct ForwardDeclared[]);
/* Dummy function, so this module contains some code. */
void dummy(void)
{
foo(NULL);
}
markg@markgordo n-lp ~
$ gcc -c t.c -ansi -pedantic
t.c:3: warning: array type has incomplete element type
Code Warrior (version 3.2.5), though, produces the following error message:
<snip>
Changing this line: void foo(struct ForwardDeclared[]); to: void foo(struct ForwardDeclared *); however, corrects the "problem".
This is a sensible change if it is meant to be a pointer to an
incomplete type. If, however, the definition of the struct is meant to
be visible in the file, making it visible before this function
declaration would be sensible.
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).
Yes. However, in every other respect in a function declaration
void foo(struct ForwardDeclared[]);
and
void foo(struct ForwardDeclared *);
are equivalent since both specify that foo takes a pointer to struct
ForwardDeclared as a parameter.
PS Posting full compilable example is, as always, the best policy when asking this sort of question.
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!
--
Flash Gordon, living in interesting times.
Web site - http://home.flash-gordon.me.uk/
comp.lang.c posting guidelines and intro: http://clc-wiki.net/wiki/Intro_to_clc
Vladimir Oka wrote: Kenneth Brody wrote: Vladimir Oka wrote: 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[]); [...] > > forwardDeclarat ion.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)?
Current versions of gcc will reject it as well.
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?
When you are able to declare a parameter as either an array type or as
a pointer type, there is absolutely no difference in its meaning.
However, that does not mean you will always be able to declare a
parameter as an array type, just because you can declare it as a
pointer type. 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.
Hmmm. I may have messed this one up.
No, I think you were right the first time.
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.
Any array of incomplete (or function) type is a constraint violation
(6.7.5.2), and so a diagnostic is required. There is no exception for
array types for function parameters.
I think you're right, and I was wrong.
Unfortunately, I don't have time at the moment to dig deeper into it (train timetables don't care about C), but I'm sure someone will.
PS I still think parameter declaration should have used pointers instead of arrays, though. A matter of style, I know, but...
On Wed, 31 May 2006 12:57:19 +0000 (UTC), Martin Eisenberg
<ma************ **@udo.edu> wrote in comp.dsp: 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[]); /* 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>mwccsym 2.exe -g -O0 -inline off -wchar_t off -align 4 -warnings on -w nohidevirtual,n ounusedexpr -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 forwardDeclarat ion.o -c forwardDeclarat ion.c forwardDeclarat ion.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.
--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.l earn.c-c++ http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
> 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 Klein" <ja*******@spam cop.net> wrote in message
news:rd******** *************** *********@4ax.c om... On Wed, 31 May 2006 12:57:19 +0000 (UTC), Martin Eisenberg <ma************ **@udo.edu> wrote in comp.dsp:
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[]); > /* 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>mwccsym 2.exe -g -O0 -inline > off -wchar_t off -align 4 -warnings on -w > nohidevirtual,n ounusedexpr -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 forwardDeclarat ion.o -c forwardDeclarat ion.c > forwardDeclarat ion.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.
-- Jack Klein Home: http://JK-Technology.Com FAQs for comp.lang.c http://c-faq.com/ comp.lang.c++ http://www.parashift.com/c++-faq-lite/ alt.comp.lang.l earn.c-c++ http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Flash Gordon wrote: Vladimir Oka wrote:
PS Posting full compilable example is, as always, the best policy when asking this sort of question.
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!
You're quite right, and I apologise to the OP.
In my defence, I dropped the code into IDE, and, by mistake, chose
Build instead of Compile Only. Then, I mixed up linker and compiler
messages. I should increase the font size and/or get new glasses.
Jack Klein wrote:
.... snip ... -- Jack Klein Home: http://JK-Technology.Com
FYI, the above site seems to be unavailable.
.... snip ... This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: mjm |
last post by:
Folks,
Please help me with the following problems:
********************************************
1. I have a class template
template<class Base> class Matrix : public Base { /* .... */ }
|
by: Steven T. Hatton |
last post by:
Should I be able to forward declare something from a namespace different
from the current one? For example the following code compiles:
//testdriver.hpp
#ifndef TESTDRIVER_HPP
#define TESTDRIVER_HPP
#include <ostream>
namespace ns_testdriver{
using std::ostream;
|
by: Markus Dehmann |
last post by:
I have a circular dependency between two classes.
The FAQ hint about a forward declaration does not help in my case
( How can I create two classes that both know about each
other?)
Error: "field `foo' has incomplete type" for the following code:
#include <iostream>
#include <vector>
|
by: Plok Plokowitsch |
last post by:
After over a decade of programming in C++ I seem to have missed some
substantial point (mental note: am I getting too old for this?). A
little bit of help would be *very* appreciated.
I'm trying to gather various different classes into a common namespace
using typedefs:
class QWidget {};
class MyListview {};
namespace gui
|
by: Michael Sgier |
last post by:
Hello
with the original code below I get the error:
"forward declaration of `struct CPlayer'"
class CPlayer; // what does this do? Instantiate the class CPlayer?
// what's a forward declaration?
class CEnemy : public CEntity
{
public:
| |
by: mark.moore |
last post by:
I know this has been asked before, but I just can't find the answer in
the sea of hits...
How do you forward declare a class that is *not* paramaterized, but is
based on a template class?
Here's what I thought should work, but apparently doesn't:
class Foo;
void f1(Foo* p)
|
by: Hunk |
last post by:
Hi
I have a question on usage of forward declarations of templates. While
searching through this group , people suggested using forward
declarations and typedefs for templates as
// in myfile.h
template<typename T,typename R>
class some_class;
|
by: Steve |
last post by:
Hi,
I always though to return an instance of a class by value, it had to be
defined - i.e. forward declaration isn't good enough?
Consider the following code snippet:
class RGBA;
class Colour
|
by: RedLars |
last post by:
Need some help with a couple of questions. Previously I have seen this
declaration;
struct Student
{
int age;
char name;
};
and this definition of an object;
struct Student stud;
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |