Last active
August 29, 2015 14:07
-
-
Save sawaken/b0fd010829adc0eebb6d to your computer and use it in GitHub Desktop.
Declaration of pointer variable with qualifier "const" in C.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* gcc 4.7.2 */ | |
#include <stdlib.h> | |
void f(int** const a) | |
{ | |
a = malloc(5 * sizeof(int)); // compile error | |
a[0] = malloc(sizeof(int)); | |
*a[0] = 100; | |
} | |
void g(int* const * a) | |
{ | |
a = malloc(5 * sizeof(int)); | |
a[0] = malloc(sizeof(int)); // compile error | |
*a[0] = 100; | |
} | |
void h(int const ** a) | |
{ | |
a = malloc(5 * sizeof(int)); | |
a[0] = malloc(sizeof(int)); | |
*a[0] = 100; // compile error | |
} | |
void h2(const int ** a) | |
{ | |
a = malloc(5 * sizeof(int)); | |
a[0] = malloc(sizeof(int)); | |
*a[0] = 100; // compile error | |
} | |
/* | |
multi qualify | |
*/ | |
void f_h(int const ** const a) | |
{ | |
a = malloc(5 * sizeof(int)); // compile error | |
a[0] = malloc(sizeof(int)); | |
*a[0] = 100; // compile error | |
} | |
/* | |
using [] | |
*/ | |
void x(int * const a[]) | |
{ | |
a = malloc(5 * sizeof(int)); | |
a[0] = malloc(sizeof(int)); // compile error | |
*a[0] = 100; | |
} | |
void y(int const * a[]) | |
{ | |
a = malloc(5 * sizeof(int)); | |
a[0] = malloc(sizeof(int)); | |
*a[0] = 100; // compile error | |
} | |
void y2(const int * a[]) | |
{ | |
a = malloc(5 * sizeof(int)); | |
a[0] = malloc(sizeof(int)); | |
*a[0] = 100; // compile error | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment