Cleaning up X server warnings
keithp.com
Cleaning up X server warnings
1–10 of 34 posts
Re: Cleaning up X server warnings
#2Interesting how the -Wcast-qual warnings are unfixable, so it shouldn't exist. Damned if you do, damned if you don't. A lot of warnings seem to fall on this.
Or warnings that would make sense on stricter languages but doesn't make sense on C exactly because of what you can do with C, like, for example, reading serialized data, then casting it to (MyStructure *)
And a little bit offtopic, but GTk have some unfixable warnings as well, something like "blah is not implemented in this platform" so, if I have to use this, but BLAH is not implemented, thanks for warning me, but shut up if I can't fix it
Re: Cleaning up X server warnings
#3Many programmers (and gcc apparently) live with the assumption that compiler warnings must always be fixed. This is largely false. Compiler warnings are there to help with additional information, not to be something to fix. There are many cases where the compiler issues a warning which must be ignored.
Many compilers support pragmas to silence a specific warning class in a specific point in the code. IMHO it's a much better approach to silence just a single warning instance where you know the compiler is getting the wrong assumption than silencing a whole warning class like the article suggests.
But it seems that in GCC you have no choice. Instead, code written with/for gcc often silences the warning by inserting some dummy code. For instance, the "unitialized warning" is usually fixed by assigning the variable to itself. It's shitty to look at, and someone that doesn't know this trick might wonder why this is being done.
I've reported a feature request many years ago, and it was quickly closed...
Re: Cleaning up X server warnings
#4It always surprised me that GCC has no source-level way of controlling compiler warnings. Many programmers (and gcc apparently) live with the assumption that compiler warnings must always be fixed. This is largely false. Compiler warnings are there to help with additional information, not to be something to fix. There are many cases where the compiler issues a warning which must be ignored. Many compilers support pra…
I recon you meant unused variables (as assinging an unitialized variable to itself would beat the purpose) you can use __attribute__((unused)) on it - normally #defined to a macro.
Re: Cleaning up X server warnings
#5It always surprised me that GCC has no source-level way of controlling compiler warnings. Many programmers (and gcc apparently) live with the assumption that compiler warnings must always be fixed. This is largely false. Compiler warnings are there to help with additional information, not to be something to fix. There are many cases where the compiler issues a warning which must be ignored. Many compilers support pra…
Also work for clang like so (replace clang with GCC for its version):
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wsomeignoredwarning"
triggered by this code
#pragma clang diagnostic popRe: Cleaning up X server warnings
#6Interesting. Interesting how the -Wcast-qual warnings are unfixable , so it shouldn't exist. Damned if you do, damned if you don't. A lot of warnings seem to fall on this. Or warnings that would make sense on stricter languages but doesn't make sense on C exactly because of what you can do with C , like, for example, reading serialized data, then casting it to (MyStructure *) And a little bit offtopic, but GTk have s…
Essentially, they are making use of const pointers to ensure that the code doesn't change the data. (gcc would throw a warning if you did). BUT: the problem comes when you want to free() the data. A strict interpretation of C would be that you can't free() something that's const, because it clearly is altering the data. However, you have to free the data sometime or other...
A possible workaround is to write a freeconst() macro that does the cast to void* and calls free(), and wrap this macro in the 'temporarily disable this warning #pragma'. This way, you only need to turn off the warning in one place in your code.
Re: Cleaning up X server warnings
#7Interesting. Interesting how the -Wcast-qual warnings are unfixable , so it shouldn't exist. Damned if you do, damned if you don't. A lot of warnings seem to fall on this. Or warnings that would make sense on stricter languages but doesn't make sense on C exactly because of what you can do with C , like, for example, reading serialized data, then casting it to (MyStructure *) And a little bit offtopic, but GTk have s…
Re: Cleaning up X server warnings
#8Re: Cleaning up X server warnings
#9Interesting. Interesting how the -Wcast-qual warnings are unfixable , so it shouldn't exist. Damned if you do, damned if you don't. A lot of warnings seem to fall on this. Or warnings that would make sense on stricter languages but doesn't make sense on C exactly because of what you can do with C , like, for example, reading serialized data, then casting it to (MyStructure *) And a little bit offtopic, but GTk have s…
The exact layout of a structure in memory is up to the compiler, and can easily change with compiler options, even if the compiler itself and the target architecture and platform remain the same.
An externally-visible serialization format should of course be stable, and not depend on the compiler used to build the code, or the hardware platform which might have ideas of how various fields should be aligned (or even how to order the bytes in integers larger than 8 bits).
Serializing data is something you do, just blindly copying the run-time representation that you have to an external medium is not serialization. You should do it field by field, with a well-defined format chosen for each field.
Re: Cleaning up X server warnings
#10Interesting. Interesting how the -Wcast-qual warnings are unfixable , so it shouldn't exist. Damned if you do, damned if you don't. A lot of warnings seem to fall on this. Or warnings that would make sense on stricter languages but doesn't make sense on C exactly because of what you can do with C , like, for example, reading serialized data, then casting it to (MyStructure *) And a little bit offtopic, but GTk have s…
Reading serialized data and then casting it into a structure type is ill-defined, very bad practice, and there's nothing in C that tells you it's a good or safe thing to be doing. So, please don't do that. The exact layout of a structure in memory is up to the compiler, and can easily change with compiler options, even if the compiler itself and the target architecture and platform remain the same. An externally-visi…