473,385 Members | 1,320 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,385 software developers and data experts.

should 'float* foo = 12345' be legal?

6.3.2.3 seems to say "yes", but 6.5.16.1 seems to say "no".

Reason I'm asking is that the Ogg Vorbis source uses this pattern, and
although it compiles fine on MSC and gcc 4, it does not compile on
Freescale's C compiler - so my question is, who's right?

Thanks.
Nov 17 '06 #1
4 1387
John <jo**@x.yywrites:
Subject: should 'float* foo = 12345' be legal?

6.3.2.3 seems to say "yes", but 6.5.16.1 seems to say "no".
6.3.2.3 says that an integer may be converted to a pointer type.
That's fine.

6.5.16.1 talks about assignment. It also applies to the
initializer you're discussing because of 6.7.8p11. The
code you're talking about does not meet the constraints in that
section, so it isn't compliant.
Reason I'm asking is that the Ogg Vorbis source uses this pattern, and
although it compiles fine on MSC and gcc 4, it does not compile on
Freescale's C compiler - so my question is, who's right?
Any compliant compiler must issue a diagnostic, because there is
a constraint violation. The compiler can then choose to produce
output or to abort, at its option--the standard doesn't say what
should happen.
--
"Some people *are* arrogant, and others read the FAQ."
--Chris Dollin
Nov 17 '06 #2
2006-11-17 <2P*******************@tornado.texas.rr.com>,
John wrote:
6.3.2.3 seems to say "yes", but 6.5.16.1 seems to say "no".

Reason I'm asking is that the Ogg Vorbis source uses this pattern,
What's the actual line?
and
although it compiles fine on MSC and gcc 4, it does not compile on
Freescale's C compiler - so my question is, who's right?

Thanks.
Nov 17 '06 #3

(For future reference: It's better to put your question
in the body of your message rather than just in the Subject
line. The display of the Subject is pretty much at the
whim of the news client or mail reader, and is sometimes
at a considerable distance from the message body -- maybe
in a different window, for example, possibly obscured from
view by the message window. For those who may wonder what
John asked, it was "should `float* foo = 12345' be legal?").

John wrote On 11/17/06 11:54,:
6.3.2.3 seems to say "yes", but 6.5.16.1 seems to say "no".
6.3.2.3 says that it is possible to make the conversion,
but not that the conversion is automatic. It is also possible
to convert "pointer to struct" to "pointer to initial element,"
but even though the conversion is permitted it doesn't mean it
"just happens."
Reason I'm asking is that the Ogg Vorbis source uses this pattern, and
although it compiles fine on MSC and gcc 4, it does not compile on
Freescale's C compiler - so my question is, who's right?
A diagnostic is required, because 6.7.8/11 says that the
initialization of a scalar is subject to the same constraints
as simple assignment, and the code at hand does not meet the
constraints of 6.5.16.1/1. Having issued a diagnostic, the
compiler is then free to behave as it likes; it may even
"compile" the diagnosable code into something useful. Then
again, it may not.

(See your gcc documentation for information about how to
get it to compile Standard C instead of "gcc C," and how to
enable its copious and helpful warnings. I'm not acquainted
with the other compilers you mention; maybe they, too, can be
made to operate in less or more loosey-goosey modes.)

If you've really no alternative except to use the vile
code pretty much as it stands, you can try

float* foo = (float*)12345;

.... despite the caveats of 6.3.2.3/5.

--
Er*********@sun.com

Nov 17 '06 #4
John <jo**@x.yywrites:
[ Subject: should 'float* foo = 12345' be legal? ]
6.3.2.3 seems to say "yes", but 6.5.16.1 seems to say "no".
6.3.2.3 says that an integer may be converted to a pointer type. It
doesn't say that such a conversion will be performed implicitly, and
in fact it won't (unless your compiler offers such an implicit
conversion as an extension).
Reason I'm asking is that the Ogg Vorbis source uses this pattern, and
although it compiles fine on MSC and gcc 4, it does not compile on
Freescale's C compiler - so my question is, who's right?
Frankly, I'd be astonished if the Ogg Vorbis source actually had a
statement like that. I'm not familiar with it, but I believe it's
supposed to be reasonable portable. For a declaration

float *foo = 12345;

to make sense, there would have to be an object of type float at that
specific address; I can't imagine why the code would make such an
assumption.

Can you show us the *actual* code you're talking about?

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 17 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Ikot | last post by:
Hello, I am stuck with a problem, might be very trivial, to ask here, but dont find a way out. I read a string like 12345.678 from a text file, which will be string for me, but how do I convert it...
20
by: ehabaziz2001 | last post by:
That program does not yield and respond correctly espcially for the pointers (*f),(*i) in print_divide_meter_into(&meter,&yds,&ft,&ins); /*--------------pnt02own.c------------ ---1 inch = 2.51...
15
by: Kay Schluehr | last post by:
I wonder why this expression works: >>> decimal.Decimal("5.5")**1024 Decimal("1.353299876254915295189966576E+758") but this one causes an error 5.5**1024 Traceback (most recent call...
7
by: Derek Basch | last post by:
How can I return: ".666" from float: "0.666" This is what I have so far:
59
by: phil-news-nospam | last post by:
In followups by Brian O'Connor (ironcorona) to other posts, he repeats the idea that using tables in CSS is not something that should be done because IE doesn't support it. Of course I'm not happy...
7
by: Stein Gulbrandsen | last post by:
What is the best way to get to the integer representation of a float? I would like to do int& toIntByCast (float& a) {return *reinterpret_cast<int*(&a);} but is this legal? Is this safer?...
2
by: ireyes | last post by:
DEAR SIR, I SAW YOUR INTERNET QUESTION AND I HAVE THE SAME TROUBLE. CUOLD YOU HELP ME TO MAKE A FLOAT TO INTEGER CONVERTION? DO YOU HAVE ANY EXEL FILE THAT CAN DO THAT? REGARDS AND THANKS A LOT ...
8
by: Ruben | last post by:
error: passing `const Weight' as `this' argument of `float Weight::wgt()' discards qualifiers seems to be some sort of standard error format that I'm not understanding. I have code that...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.