473,406 Members | 2,220 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Stupid compiler


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
6 987
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Matthew Del Buono | last post by:
Don't try to solve the problem. I've found a way -- around or fixing it. I'm just curious as to whether this is Microsoft's problem in their compiler or if there's a standard saying this is to be...
5
by: raz | last post by:
Greetings all. I apologize for what is almost certainly a stupid question, but I can't figure this out, and have no more time for head bashing... The short version: what is the appropriate...
21
by: JKop | last post by:
Today I wrote a function that returned an "std::ostringstream" by value. I compiled it with G++. It was throwing exceptions at run-time and closing. So I look through the code, and I look...
36
by: Hoopster | last post by:
Hello, I know nothing about C++ but want to get started. Is there any good free C++ program that I can try to see if I like programming? I also need a good free compiler. I don't want to...
2
by: Lampa Dario | last post by:
Hi, where is this stupid error in this program? When I execute it, i receive a segmentation fault error. #include <stdio.h> int main(int argc, char *argv, char *env) { int i=0; int l=0; int...
3
by: Bill | last post by:
I am confused why I must cast an enum to a type int if I defined the enum as follows: enum COLUMNS :int { IP=0, MSG =1 } IMHO the compiler should be able to make the conversion without...
6
by: Malvolio | last post by:
I know this is a *really* stupid question but what the hell is visual c++? I downloaded it and it doesn't seem to work. It isn't like any c++ compiler I ever saw before and the manual on the...
5
by: Puppet_Sock | last post by:
So, I'm madly coding away, and my fingers stutter, and I produce this. (mfirstToken is a std::string object.) if(m_firstToken.c_str() == 'M' || m_firstToken.c_str().c_str() == 'T') { // ......
7
by: ot_007_2001 | last post by:
Hi, all, For pricticing defination of structure in C, I wrote a small code as follow: #include<stdio.h> struct datastruct { int data;
10
by: Chris Becke | last post by:
In C and in older C++ compilers, you could write code like this void a(void** pp); // declare a function that takes a pointer to a pointer-to-void. struct I {}; // some struct. I *i1,**i2; //...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
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,...
0
tracyyun
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...
0
isladogs
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.