By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,330 Members | 1,443 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,330 IT Pros & Developers. It's quick & easy.

Stupid compiler

P: n/a

int main()
{
float blah( float() );

blah = 5.2;
}
Why the hell does g++ think that that's a function declaration?!

It's telling me that I can't assign a value to a function!

Is this a bug in g++?
-JKop
Jul 22 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
On Mon, 09 Aug 2004 17:54:10 GMT, JKop <NU**@NULL.NULL> wrote:

int main()
{
float blah( float() );

blah = 5.2;
}
Why the hell does g++ think that that's a function declaration?!

It's telling me that I can't assign a value to a function!

Is this a bug in g++?
-JKop

No, remember parameter names are optional in C++.

float blah(float x);

same as

float blah(float (x));

same as

float blah(float ());

Try this

float blah = float();

No confusion possible.

john
Jul 22 '05 #2

P: n/a
JKop wrote:

int main()
{
float blah( float() );

blah = 5.2;
}
Why the hell does g++ think that that's a function declaration?!


Return Type
| Function name
| | Argument Type (a parameterless fn that returns a float)
| | |
V V V
float blah ( float() )

C++ Rule In Case Of Ambiguities:
"If it Looks like declaration, it is a declaration."

Write 'float blah=float();' instead. It means exactly the same as your
intent was with 'float blah(float())'

Marco

Jul 22 '05 #3

P: n/a
On Mon, 09 Aug 2004 20:05:33 +0200, Marco Manfredini <no****@phoyd.net>
wrote:
JKop wrote:

int main()
{
float blah( float() );

blah = 5.2;
}
Why the hell does g++ think that that's a function declaration?!


Return Type
| Function name
| | Argument Type (a parameterless fn that returns a float)
| | |
V V V
float blah ( float() )

C++ Rule In Case Of Ambiguities:
"If it Looks like declaration, it is a declaration."

Write 'float blah=float();' instead. It means exactly the same as your
intent was with 'float blah(float())'

Marco


I tested it, your interpretation is right, mine is wrong.

float blah(float (x));

is a function taking one float as an argument, but when x is removed the
parens change meaning and become part of the type of the parameter to blah.

Change it to

float blah(float (()));

And then both interpretations of the parens are present.

john
Jul 22 '05 #4

P: n/a
On Mon, 09 Aug 2004 11:10:18 -0700, John Harrison wrote:
No, remember parameter names are optional in C++.

float blah(float x);

same as

float blah(float (x));
So far so good.

same as

float blah(float ());


I don't think so. The parameter is a function pointer in this
case. (I couldn't have possibly known this until I tried. :)

Ali
Jul 22 '05 #5

P: n/a
On Mon, 09 Aug 2004 17:54:10 GMT, JKop <NU**@NULL.NULL> wrote:

int main()
{
float blah( float() );

blah = 5.2;
}
Why the hell does g++ think that that's a function declaration?!

It's telling me that I can't assign a value to a function!

Is this a bug in g++?


In addition to the other posts, another version is:

float blah((float()));

which is even more ugly. Note that didn't work prior to GCC 3.4, and
stands as the one and only GCC bug report I have made!

Tom
Jul 22 '05 #6

P: n/a
tom_usenet posted:
On Mon, 09 Aug 2004 17:54:10 GMT, JKop <NU**@NULL.NULL> wrote:

int main()
{
float blah( float() );

blah = 5.2;
}
Why the hell does g++ think that that's a function declaration?!
It's telling me that I can't assign a value to a function!
Is this a bug in g++?
In addition to the other posts, another version is:

float blah((float()));

which is even more ugly. Note that didn't work prior to

GCC 3.4, and stands as the one and only GCC bug report I have made!

Tom


....and a hope you gave me credit!
-JKop
Jul 22 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.