Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
more falafel please
Feb 26, 2005

forums poster

Polio Vax Scene posted:

my first reaction was "well then the sqrt should check for float input and automatically call sqrtf and only do the expansion if explicitly requested in the call" but now I'm thinking it's probably better to do the opposite and live with hunting down the performance impact and not cause something to explode at NASA

then again slow performance could also cause something to explode at NASA

It's mindboggling that -Wdouble-promotion isn't included in -Wall, but you should be using it

Adbot
ADBOT LOVES YOU

leper khan
Dec 28, 2010
Honest to god thinks Half Life 2 is a bad game. But at least he likes Monster Hunter.

more falafel please posted:

It's mindboggling that -Wdouble-promotion isn't included in -Wall, but you should be using it

I should probably re-evaluate my warning lists

Anything useful not in -Wall -Wextra -Wpedantic

Or useful things I'd be missing with those enabled? Mostly been writing C for late 90s and early 2000s handheld game consoles.

Spatial
Nov 15, 2007

Double promotion warnings can be really handy when developing for microcontrollers that only support single precision. Soft double vs hard float is a stark difference in performance.

Athas posted:

I have spent too much of my life chasing down performance bugs because some C code dared to call sqrt(x) where x was a float, because sqrt() is defined for doubles, and so this involves a silent expansion to double precision and a full double precision square root. (The solution is to use sqrtf() instead.)
I found a good one of these lately where someone was calling pow() instead of powf() inside an inner inner loop. 10% of runtime knocked off with a single character. :v:

Xarn
Jun 26, 2015
It's always fun to see significantly different worlds in term of target hw. We target broadwell as minimum due to the instruction set, and our baseline expectation is ~4 gigs of ram per core. :v:

leper khan
Dec 28, 2010
Honest to god thinks Half Life 2 is a bad game. But at least he likes Monster Hunter.

Xarn posted:

It's always fun to see significantly different worlds in term of target hw. We target broadwell as minimum due to the instruction set, and our baseline expectation is ~4 gigs of ram per core. :v:

Current target has 64K ram. Max artifact size is a couple megabit

more falafel please
Feb 26, 2005

forums poster

My minspec is Nintendo Switch, although the project I'm on now runs on very low spec PCs, so something like 2GB total memory usage is the budget. Of course on consoles the hardware is fixed and well understood, so we can use whatever is there.

Doom Mathematic
Sep 2, 2008

NihilCredo posted:

I think what +0 really means is "a number between 0 and 2 ^ -126", and -0 really means "a number between - (2 ^ -126) and 0". Or maybe -127 depending how you do rounding.

This is a common misconception, or is that the joke?

Presto
Nov 22, 2002

Keep calm and Harry on.
In 25 years of programming for dollars I have only ever had 1 problem stemming from floats, and that was in some third-party code that was comparing floats directly with ==. It worked OK in gcc <N> and then started failing in gcc <N+1>.

Absurd Alhazred
Mar 27, 2010

by Athanatos
I've run into precision issues in graphics shaders.

more falafel please
Feb 26, 2005

forums poster

I had precision issues one time when I was porting a custom C++ game engine to C# for reasons that are way too stupid to go into here (short version: had to be on Windows Phone 7, which didn't allow any native code). A bunch of math functions in C# land are double-only, and transcribing a relatively simple expression could end up converting from float->double->float like 6 or 8 times. Converting all the inputs to double at the start and then converting the result to float made the error basically go away. Again, the sort of thing that would only happen when you're transcribing code that's supposed to be floats all the way down to a mixed environment.

Foxfire_
Nov 8, 2010

leper khan posted:

I should probably re-evaluate my warning lists

Anything useful not in -Wall -Wextra -Wpedantic

Or useful things I'd be missing with those enabled? Mostly been writing C for late 90s and early 2000s handheld game consoles.
Some more:
-Wformat-nonliteral: Warn if a printf/scanf format string is not a string literal (or set -Wformat=2 instead of the default you'll get with Wall)
-Wcast-qual: Warn if a cast discards a qualifier (i.e. const int* => int*)
-Wconversion: Warn on implicit conversions that potentially change values (i.e. abs(2.1))

ullerrm
Dec 31, 2012

Oh, the network slogan is true -- "watch FOX and be damned for all eternity!"

Foxfire_ posted:

Some more:
-Wformat-nonliteral: Warn if a printf/scanf format string is not a string literal (or set -Wformat=2 instead of the default you'll get with Wall)
-Wcast-qual: Warn if a cast discards a qualifier (i.e. const int* => int*)
-Wconversion: Warn on implicit conversions that potentially change values (i.e. abs(2.1))

These are good. Some other good ones we use that are not too noisy:

* -Wformat-type-confusion: Warn if an argument to printf() doesn't match the expected type for the placeholder.
* -Wconditional-uninitialized: Warn if a variable is uninitialized upon use/capture.
* -Widiomatic-parentheses: Warn if you use the result of an assignment without explicitly wrapping it in parens. (This catches "if (x = 10)" style typos.)
* -Wbad-function-cast: Warn if you cast fxnptrs to incompatible types.
* -Wunreachable-code: Warns if you've got code that will never be executed.

Some stuff that is noisier but might be worthwhile depending on your tolerance:

* -Wswitch-enum: Warns if you have a switch on an enum and don't cover all cases of the enum, either with explicit cases or default.
* -Wimplicit-fallthrough: Warns if you have a fall-through between switch cases without using [[fallthrough]].
* -Wfloat-equal: Warn if comparing floating-point types with ==/!=.

HappyHippo
Nov 19, 2003
Do you have an Air Miles Card?
I love that -Wall doesn't enable all warnings

Absurd Alhazred
Mar 27, 2010

by Athanatos
-Wsome

b0lt
Apr 29, 2005
You can get all sorts of fun memory corruption if you break invariants on things like std::sort or std::set by passing in data that isn't actually strictly ordered by std::less.

toiletbrush
May 17, 2010

Presto posted:

In 25 years of programming for dollars I have only ever had 1 problem stemming from floats, and that was in some third-party code that was comparing floats directly with ==. It worked OK in gcc <N> and then started failing in gcc <N+1>.
ask me about my previous job where they wrote their new finance reconciliation :smuggo:microservice:smuggo: using typescript and the problems we had with it

ps. don't ask me about it

more falafel please
Feb 26, 2005

forums poster

HappyHippo posted:

I love that -Wall doesn't enable all warnings

It's ridiculous, but if -Wall did enable all warnings, no one would use it. I don't think I've ever worked on a project that would pass -Wunreachable-code, for instance, and no one is gonna have time to get rid of all the unreachable code in, say, UE4

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
-Weverything actually does turn on all warnings with clang, and using it requires turning a bunch of warnings back off.

more falafel please posted:

It's ridiculous, but if -Wall did enable all warnings, no one would use it. I don't think I've ever worked on a project that would pass -Wunreachable-code, for instance, and no one is gonna have time to get rid of all the unreachable code in, say, UE4

That's uh, kinda strange. -Wunreachable-code only catches things like code after an unconditional return and a codebase that'd be difficult to get passing it is in really dire shape.

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
You've never used macros that contain a conditional, and the value passed into the macro is sometimes a constant?

Dylan16807
May 12, 2010
My favorite floating point problem was helping someone debug their lua code for some game plugin and realizing that somehow all comparisons with NaN were returning true.

Zopotantor
Feb 24, 2013

...und ist er drin dann lassen wir ihn niemals wieder raus...

-Wjust-those-that-trigger-on-jeffs-code-but-not-those-which-trigger-on-mine

ToxicFrog
Apr 26, 2008


Dylan16807 posted:

My favorite floating point problem was helping someone debug their lua code for some game plugin and realizing that somehow all comparisons with NaN were returning true.

:whoptc:

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe

Plorkyeran posted:

-Weverything actually does turn on all warnings with clang, and using it requires turning a bunch of warnings back off.

The recommended use pattern is to periodically turn it on to find interesting warnings, turn those on, and then turn it back off in your regular builds.

Probably not a bad idea to also accumulate the warnings you’re definitely not interested in so you don’t waste your time with them when you repeat this investigation.

ultrafilter
Aug 23, 2007

It's okay if you have any questions.


There are options to disable warnings for specific blocks of code through the preprocessor. They're not standard across compilers but at least gcc and clang agree on how to do them. Maybe it'll be in the standard someday.

Doc Hawkins
Jun 15, 2010

Dashing? But I'm not even moving!


leper khan
Dec 28, 2010
Honest to god thinks Half Life 2 is a bad game. But at least he likes Monster Hunter.

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed

Jabor posted:

You've never used macros that contain a conditional, and the value passed into the macro is sometimes a constant?

Clang does not warn about unreachable code inside macro expansion.

more falafel please
Feb 26, 2005

forums poster

Plorkyeran posted:

-Weverything actually does turn on all warnings with clang, and using it requires turning a bunch of warnings back off.

That's uh, kinda strange. -Wunreachable-code only catches things like code after an unconditional return and a codebase that'd be difficult to get passing it is in really dire shape.

Hmm, ok. I'm probably conflating the clang flag with like, a full fledged linter. I've never tried turning -Weverything on on UE4, it might be fun (it would not be fun)

Xarn
Jun 26, 2015
The problem with just Weverything for large codebases is that everything will get buried under an absolute fuckton of Wc++98-compat, so turn that off first :v:

You will also find a bunch of warnings that are very heuristical and will need to ignore, but sometimes it does find useful stuff.

Athas
Aug 6, 2007

fuck that joker

Xarn posted:

It's always fun to see significantly different worlds in term of target hw. We target broadwell as minimum due to the instruction set, and our baseline expectation is ~4 gigs of ram per core. :v:

It's not just a footprint thing. I do high performance computing, and if you unnecessarily use double precision, you'll lose half your memory bandwidth and half your SIMD lanes. Storage capacity isn't so important.

And of course, on commodity GPUs the loss is even more stark due to market segmentation (I think double precision is something like 32x or 64x slower on NVIDIAs commodity GPUs these days).

redleader
Aug 18, 2005

Engage according to operational parameters

toiletbrush posted:

ask me about my previous job where they wrote their new finance reconciliation :smuggo:microservice:smuggo: using typescript and the problems we had with it

ps. don't ask me about it

you are in a safe space. share your pain, friend

Ola
Jul 19, 2004

A dumb question: Isn't there huge amounts of user friendly tooling that makes C easy and safe by now?

Athas
Aug 6, 2007

fuck that joker

Ola posted:

A dumb question: Isn't there huge amounts of user friendly tooling that makes C easy and safe by now?

It's not user friendly. As a small example, the last few pages of this thread lists important warning that are not turned on by default, and also not turned on when you ask for "all" warnings.

Ola
Jul 19, 2004

Athas posted:

It's not user friendly. As a small example, the last few pages of this thread lists important warning that are not turned on by default, and also not turned on when you ask for "all" warnings.

But that's the compiler. I was thinking you could do this in VS Code or some snazzy JetBrains product where friendly plugins would shower you with sage advice.

DoctorTristan
Mar 11, 2006

I would look up into your lifeless eyes and wave, like this. Can you and your associates arrange that for me, Mr. Morden?

Ola posted:

But that's the compiler. I was thinking you could do this in VS Code or some snazzy JetBrains product where friendly plugins would shower you with sage advice.

“Surely that’s been fixed by now” is a question asked many times. The answer is (almost) always the same.

Spatial
Nov 15, 2007

Ola posted:

A dumb question: Isn't there huge amounts of user friendly tooling that makes C easy and safe by now?
:xd:

leper khan
Dec 28, 2010
Honest to god thinks Half Life 2 is a bad game. But at least he likes Monster Hunter.

Ola posted:

But that's the compiler. I was thinking you could do this in VS Code or some snazzy JetBrains product where friendly plugins would shower you with sage advice.

I like clion. But mostly because it makes finding docs easier and matches the workflows I have in C#. It does not prevent me from being Very Dumb any more than the compiler did before.

Recently I burned a day to it's non-standard cmake targets support. And another day to cmake trying (and failing) to get a targets file set up for my compilers. I've decided to just stick with makefiles, which are recently supported in clion anyway. Granted, I'm using really weird tool chains (I'd be surprised if there were dozens of people working with them today).

ExcessBLarg!
Sep 1, 2001

Jabor posted:

You've never used macros that contain a conditional, and the value passed into the macro is sometimes a constant?
Err, no. I don't think I have. That's a weird thing to do.

Winter Stormer
Oct 17, 2012

ExcessBLarg! posted:

Err, no. I don't think I have. That's a weird thing to do.

assert(0)? assert(!"bad foo in bar()")? I don't think it's that weird or uncommon.

Adbot
ADBOT LOVES YOU

ExcessBLarg!
Sep 1, 2001

Winter Stormer posted:

assert(0)? assert(!"bad foo in bar()")? I don't think it's that weird or uncommon.
OK, yes, asserts. That's an edge case but it does validate the point. I can't think of another instance where I intentionally do that though.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply