Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

-std=c99 my anus

Name: Anonymous 2009-11-25 15:29

[code]$cat test.c
#include <stdlib.h>
#include <string.h>

int main(void) {
    char *foo;
    foo = strdup("bar");
    free(foo);
    return 0;
}
$gcc test.c
$gcc -std=c99 test.c
test.c: In function 'main':
test.c:6: warning: implicit declaration of function 'strdup'
test.c:6: warning: assignment makes pointer from integer without a cast[code]
What the heck is this, /prog/? Is there some shit around strdup() in c99?

Name: Anonymous 2009-11-30 3:08

>>39
When was the last time someone accepted your const data and then mangled data it referred to in an unexpected manner? I'm guessing never. People who write APIs like that don't acquire many users.
Is that why sepples has the mutable keyword? A significant number of people had to want to mutate data in a const struct in order to get this into the standard.

Besides, it's almost always unintentional. You change the behaviour of a function to modify pointed data, not realizing it was meant to be const. This works for a while until someone changes something else and triggers a bug, and days are spent figuring out what's going on. The compiler of course is perfectly happy.

Your whole argument presumes that people will notice the const and manually follow additional, unverifiable rules to respect it. So what's the point of const if it's worse than good documentation and simple code comments? Why was it added to the standard at all?

You can also provide the struct anonymously in the function. If you don't want to cast, try using onion.
You still need to cast. Transparent unions are not standardized in any way. In GCC you have to give the union a special attribute to allow implicit casting.

>>36
(Of course none of this is practical.)
Congratulations, that is the exact problem with const. While it is technically possible to make it propagate as it should, you have to do it by hand, and so it is infeasible. The maintenance problems with duplicating all your structs are worse than just not using const (in C, not sepples unfortunately since STL uses it). And these structs are still incompatible according to standard C!

Are you folks going to admit that const is broken yet?

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List