prism icon indicating copy to clipboard operation
prism copied to clipboard

Should Prism use -std=gnu99 instead of -std=c99?

Open eregon opened this issue 2 years ago • 5 comments

I noticed https://github.com/ruby/rbs/commit/67a6acaa0f62a5f984cbf4a54a35600da0d1467f I wonder if it might be a bit faster with -std=gnu99. Not sure if -std=gnu99 is accepted on Windows, but probably yes if gcc is used on Windows (MSYS2).

eregon avatar Oct 13 '23 09:10 eregon

Interesting. Can we detect if it's gcc and use it conditionally?

kddnewton avatar Oct 13 '23 12:10 kddnewton

I'm not sure, maybe @nurse would know since he authored that change? I think we should first check if it changes anything performance-wise, maybe those builtins are not used or are not performance-critical for YARP.

eregon avatar Oct 13 '23 16:10 eregon

As I wrote the commit comment, -std=c99 disable some optimizations. Unless you have a specific reason to disable such optimizations, you should use -std=gnu99. Note that as far as I understand -std=c99 doesn't provide you more portability. Don't use -std=c99 unless you have a specific reason.

nurse avatar Dec 06 '23 16:12 nurse

Note that as far as I understand -std=c99 doesn't provide you more portability.

Do you mean better to not specify any -std=, do you mean -std=gnu99 is as portable as -std=c99?

I guess both gcc and clang support -std=gnu99, but MSVC probably not. But MSVC does not even support -std= probably, it uses a slightly different syntax IIRC.

eregon avatar Dec 06 '23 18:12 eregon

Sorry I'm not entirely clear. Is it safe to replace c99 with gnu99? I'm happy to do that, I just don't want to break anything...

It appears from some cursory research that gnu99 is c99 + specific GNU extensions. The whole reason we went with c99 in the first place was to ensure we didn't accidentally try to use GNU extensions because we were failing to compile on some machines.

We probably should have an optimized versus debug build anyway, maybe for local development we use c99 without optimizations and for the gem we use gnu99 with optimizations. Would that make sense?

kddnewton avatar Dec 06 '23 19:12 kddnewton

Going to close this for now until we have more information

kddnewton avatar May 24 '24 15:05 kddnewton