Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- char **a;
- const char** b = a;
- char **a;
- const char* const* b = a;
- void f(const char* const* in) {
- // Only reads the data from in, does not write to it
- }
- void foo(const int*);
- char *y;
- char **a = &y; // a points to y
- const char **b = a; // now b also points to y
- // const protection has been violated, because:
- const char x = 42; // x must never be modified
- *b = &x; // the type of *b is const char *, so set it
- // with &x which is const char* ..
- // .. so y is set to &x... oops;
- *y = 43; // y == &x... so attempting to modify const
- // variable. oops! undefined behavior!
- cout << x << endl;
- char **a;
- const char* const* b = a;
- const char **a;
- const char* const* b = a;
- char **a;
- const char* const* b = (const char **)a;
- #include <stdlib.h>
- #include <stdio.h>
- void foo(const char * const * bar)
- {
- printf("bar %s nulln", bar ? "is not" : "is");
- }
- int main(int argc, char **argv)
- {
- char **x = NULL;
- const char* const*y = x;
- foo(x);
- foo(y);
- return 0;
- }
- test.c(8) : warning C4100: 'argv' : unreferenced formal parameter
- test.c(8) : warning C4100: 'argc' : unreferenced formal parameter
- test.c(8) : warning C4100: 'argv' : unreferenced formal parameter
- test.c(8) : warning C4100: 'argc' : unreferenced formal parameter
- test2.c: In function `main':
- test2.c:11: warning: initialization from incompatible pointer type
- test2.c:12: warning: passing arg 1 of `foo' from incompatible pointer type
- char c = 'c';
- char *p = &c;
- char **a = &p;
- const char *bi = *a;
- const char * const * b = &bi;
- const volatile int *const serial_port = SERIAL_PORT;
- char *const p = (char *) 0xb000;
- //error: p = (char *) 0xc000;
- char **q = (char **)&p;
- *q = (char *)0xc000; // p is now 0xc000
- void foo (const char* const& x);
Add Comment
Please, Sign In to add comment