Skip to main content
GameDev.net gamedev.net
🔒 Locked

c/c++ warnings

Started by ehmdjii Feb 27, 2005 at 12:07 PM 6 replies 1.2k views
Original Post
ehmdjii
ehmdjii
i have a project that uses c++ as well as normal c files. the code compiles fine, but sometimes when i change some little part of the code, a completely other part triggers warnings. (mostly conversions from double to float) for example i define a triangle mesh in a c file like this:

static float Cylinder01_coords[] = {
    10.001, 0.001, -0.001,
    9.39793, 0.001, -3.4212,
    0.001, 0.001, -0.001,
    // and 1000 lines so on...
}

this gives me thousands of doubletofloat-warnings and is pretty annoying. anyone knows what is causing this? thanks!
ProPuke
ProPuke
Yes - You are converting double-precision numbers to single precision floating.
10.001 is double
10.001f is float
(just put an f on the end of the numbers to make them single precision)
I know it seems silly but that's the way C++ is. I've often thought that compilers should automaticly guess conversions of "close" constants like that, but sadly you still have to be exact in the typing yourself

push{  Prehaps:    1) Select region of numbers    2) Ide autoreplace "," -> "f," within selection  Does your ide support something like that?}
____ _ ___ ___ __ _`By offloading cognitive load to the computer, programmers are able to design more elegant systems' - Unununium OS regarding Python
smart_idiot
smart_idiot
Write the numbers as 10.001f, 0.001f, -0.001f. . . ?
Chess is played by three people. Two people play the game; the third provides moral support for the pawns. The object of the game is to kill your opponent by flinging captured pieces at his head. Since the only piece that can be killed is a pawn, the two armies agree to meet in a pawn-infested area (or even a pawn shop) and kill as many pawns as possible in the crossfire. If the game goes on for an hour, one player may legally attempt to gouge out the other
Kippesoep
Kippesoep
To prevent having to fix every float manually, you can use a regular expression find and replace (assuming Visual Studio): replace
\(\:n\)

with
\1f


(make sure the "regular expression" checkbox is ticked.
Kippesoep
ehmdjii
ehmdjii
thanks, but is this the only solution.

the file comes from the Anim8or exporter. i wonder that it exports "false" syntax.


another question:
why does this give a warning:

mymeshstruct *meshes[];

(null-array warning)
Conner McCloud
Conner McCloud
That's the only solution to actually remove the warning. There might be some command line argument that will cause the compiler to ignore that particular issue, although I can't think of one off hand. In Visual studio, you can use a pragma directive to do the trick:

#pragma warning(push)#pragma warning(disable, 101010) //101010 is the warning number, just insert whatever you're actually seeing.//offending code goes here#pragma warning(pop)


As for your other question, you use [] to specify that you are using a constant length, but the compiler an figure it out on it's own. So 'char str[] = "abc"' will result in the same as 'char str[4] = "abc"'. You need to initialize the array at the declaration, or the compiler won't be able to figure out the proper length.

CM
Zahlman
Zahlman
Quote:
Original post by ehmdjii
thanks, but is this the only solution.

the file comes from the Anim8or exporter. i wonder that it exports "false" syntax.



IMHO, tools that "export" data "as code" are evil. If it's supposed to be data, you should be reading it in from a data file.
MaulingMonkey
MaulingMonkey
Quote:
Original post by Zahlman
Quote:
Original post by ehmdjii
thanks, but is this the only solution.

the file comes from the Anim8or exporter. i wonder that it exports "false" syntax.



IMHO, tools that "export" data "as code" are evil. If it's supposed to be data, you should be reading it in from a data file.


They're the poor(table) man's resource files. There are some occasions that having built in data isn't all that bad (icons, some texts, targeted for embedded platforms...) meaning the tools in and of themselves arn't evil. But I do agree that most of the time you should be reading the data froma file :).

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.