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: Anonymous 2012-01-19 18:36

>>15

#include <stdio.h>

int main(int argc, char **argv) {
    char a[argc];
    printf("%zu\n", sizeof a);
    return 0;
}


So, shouldn't that actually output sizeof (char *), given a is evaluated (since it's a VLA) and the value of an array is a pointer to its first element?

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