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-12-01 10:25

>>56
const volatile makes perfect sense actually.
const is a promise you make to the compiler that YOU won't be changing that location, this won't stop the OS/hardware/BIOS/other applications, or even some other thread or non-standard code(for example, someone's library) from changing it. A common usage would be a clock/tick count location the OS updates, but which you shouldn't change (as it would be meaningless in the best scenario, or harmful in the worst(page protection or hardware registers or whatever)).
volatile is used to tell the compiler the location may be changed by outside events/code, so it should be careful about what optimizations it does and that it should always use a reference when refering to that location.
A const volatile would mean a location in memory that may be changed by something else other than your code, but which should not be modified by your code at all.

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