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

C problem

Name: Anonymous 2012-01-18 19:35

Is the behaviour of this program well defined?

#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>

int main() {
    size_t num, min, max;
    if(scanf("%zu%zu%zu", &num, &min, &max) != 3) return 0;
    if(min >= num || max >= num || min > max) return 0;
    int *arr = calloc(num, sizeof(*arr));
    if(!arr) return 0;
    int *x = arr + min, *y = arr + max, *z = arr + (y - x);
    *x = 1, *y = 1, *z = 1;
    return 0;
}

Name: kodak_galllery_programmer !!kCq+A64Losi56ze 2012-01-22 11:59

>>49
So in other words, could it be....

no way....


wait for it...













YOU MIGHT NOT ONLY HAVE UNDEFINED BEHAVIOR, BUT YOU WILL MIGHT ALSO HAVE A MEMORY LEAK.




WELCOME TO C. THE LANGUAGE THE PROVIDES YOU WITH ENOUGH TOOLS TO FUCK YOURSELF.

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