Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Will the code actually work? -Werror just means treat warning as errors, so removing it would give you a warning instead, but just because the compiler is giving you a warning doesnt mean the code wont do what you want it to. A warning is just a warning, it is not an error
Of course it work, if:
- I make : char* str = (char*)"HELLO WORLD!" instead. See, (char*). And everytime I want to write a string, (char*) again.
- Or delete -Werror and pretend not to care about it.
Everyone know warnings is warnings, but I hate them. Because warnings can suddenly turn into errors and nobody can find that goddamn bug.
Read the manual for GCC, it looks like you have somehowe enabled:
* Warnings are errors (as stated).
* Make string literals const char[] (-Wwrite-strings).
* Warn for casting away cv-qualifiers (-Wcast-qual).
Basically modifying a string literal has undefined/implementation-defined behavior. IFAIK with GCC you'll have some problems here. The string literal ends up in the .rodata section which is for read-only data. You could of course map the read-only data to read-write pages and you should be able to modify the literal, but you'd be able to modify all constant data as well. To avoid this you could put all modifiable string literals in one file and use link scripts to put the .rodata section from these in a read-write data section in the output. However in most cases you don't need/want to modify the string literals.
And hiding warnings is a Bad Idea(tm), fix them. That's what "warnings as errors" (-Werror) is for - to force you to stick to good coding practices.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Combuster wrote:And hiding warnings is a Bad Idea(tm), fix them. That's what "warnings as errors" (-Werror) is for - to force you to stick to good coding practices.
That's why I keep sticking with -Werror, although it keep kicking my @$$
"Programmers are tools for converting caffeine into code."