0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

const test。docker(136)

Last updated at Posted at 2020-03-18
const.c
#include <stdio.h>
#define PR(a) printf("%" #a " = " , a)

int main(){

int hoge1=1;
int * hoge2;
int * const hoge3;
const int * hoge4;
int const * hoge5;
const int * const hoge6;
const int const * hoge7;

hoge2= &hoge1;
hoge3 = &hoge1;
hoge4 = &hoge1;
hoge5 = &hoge1;
hoge6 = &hoge1;
PR(hoge1);
PR(hoge2);
PR(hoge3);
PR(hoge4);
PR(hoge5);
PR(hoge6);

hoge3 = &hoge2;
hoge4 = &hoge2;
hoge5 = &hoge2;
hoge6 = &hoge2;
PR(hoge3);
PR(hoge4);
PR(hoge5);
PR(hoge6);
hoge4 = &hoge3;
hoge5 = &hoge3;
hoge6 = &hoge3;
PR(hoge3);
PR(hoge4);
PR(hoge5);
PR(hoge6);
hoge3 = &hoge4;
hoge5 = &hoge4;
hoge6 = &hoge4;
PR(hoge3);
PR(hoge4);
PR(hoge5);
PR(hoge6);
hoge3 = &hoge5;
hoge4 = &hoge5;
hoge6 = &hoge5;
PR(hoge3);
PR(hoge4);
PR(hoge5);
PR(hoge6);
hoge3 = &hoge6;
hoge4 = &hoge6;
hoge5 = &hoge6;

PR(hoge3);
PR(hoge4);
PR(hoge5);
PR(hoge6);
}

compile

docker/ubuntu
# gcc const.c
const.c: In function 'main':
const.c:15:7: error: assignment of read-only variable 'hoge3'
   15 | hoge3 = &hoge1;
      |       ^
const.c:18:7: error: assignment of read-only variable 'hoge6'
   18 | hoge6 = &hoge1;
      |       ^
const.c:26:7: error: assignment of read-only variable 'hoge3'
   26 | hoge3 = &hoge2;
      |       ^
const.c:27:7: warning: assignment to 'const int *' from incompatible pointer type 'int **' [-Wincompatible-pointer-types]
   27 | hoge4 = &hoge2;
      |       ^
const.c:28:7: warning: assignment to 'const int *' from incompatible pointer type 'int **' [-Wincompatible-pointer-types]
   28 | hoge5 = &hoge2;
      |       ^
const.c:29:7: error: assignment of read-only variable 'hoge6'
   29 | hoge6 = &hoge2;
      |       ^
const.c:34:7: warning: assignment to 'const int *' from incompatible pointer type 'int * const*' [-Wincompatible-pointer-types]
   34 | hoge4 = &hoge3;
      |       ^
const.c:35:7: warning: assignment to 'const int *' from incompatible pointer type 'int * const*' [-Wincompatible-pointer-types]
   35 | hoge5 = &hoge3;
      |       ^
const.c:36:7: error: assignment of read-only variable 'hoge6'
   36 | hoge6 = &hoge3;
      |       ^
const.c:41:7: error: assignment of read-only variable 'hoge3'
   41 | hoge3 = &hoge4;
      |       ^
const.c:42:7: warning: assignment to 'const int *' from incompatible pointer type 'const int **' [-Wincompatible-pointer-types]
   42 | hoge5 = &hoge4;
      |       ^
const.c:43:7: error: assignment of read-only variable 'hoge6'
   43 | hoge6 = &hoge4;
      |       ^
const.c:48:7: error: assignment of read-only variable 'hoge3'
   48 | hoge3 = &hoge5;
      |       ^
const.c:49:7: warning: assignment to 'const int *' from incompatible pointer type 'const int **' [-Wincompatible-pointer-types]
   49 | hoge4 = &hoge5;
      |       ^
const.c:50:7: error: assignment of read-only variable 'hoge6'
   50 | hoge6 = &hoge5;
      |       ^
const.c:55:7: error: assignment of read-only variable 'hoge3'
   55 | hoge3 = &hoge6;
      |       ^
const.c:56:7: warning: assignment to 'const int *' from incompatible pointer type 'const int * const*' [-Wincompatible-pointer-types]
   56 | hoge4 = &hoge6;
      |       ^
const.c:57:7: warning: assignment to 'const int *' from incompatible pointer type 'const int * const*' [-Wincompatible-pointer-types]
   57 | hoge5 = &hoge6;
      |       ^
const2.c

#include <stdio.h>
#define PR(a) printf("%" #a " = " , a)

int main(){

int hoge1=1;
int * hoge2;
int * const hoge3=&hoge1;
const int * hoge4;
int const * hoge5;
const int * const hoge6=&hoge3;
const int const * hoge7;

hoge2= &hoge1;
hoge4 = &hoge1;
hoge5 = &hoge1;
hoge7 = &hoge1;
PR(hoge1);
PR(hoge2);
PR(hoge3);
PR(hoge4);
PR(hoge5);
PR(hoge6);

hoge4 = &hoge2;
hoge5 = &hoge2;
hoge7 = &hoge2;
PR(hoge2);
PR(hoge4);
PR(hoge5);
PR(hoge7);
hoge2 = &hoge3;
hoge4 = &hoge3;
hoge5 = &hoge3;
hoge7 = &hoge3;
PR(hoge2);
PR(hoge4);
PR(hoge5);
PR(hoge7);
hoge2 = &hoge4;
hoge5 = &hoge4;
hoge7 = &hoge4;
PR(hoge2);
PR(hoge5);
PR(hoge7);
hoge2 = &hoge5;
hoge4 = &hoge5;
hoge7 = &hoge5;
PR(hoge2);
PR(hoge4);
PR(hoge7);
hoge2 = &hoge6;
hoge4 = &hoge6;
hoge5 = &hoge6;
hoge7 = &hoge6;
PR(hoge3);
PR(hoge4);
PR(hoge5);
PR(hoge6);
hoge2 = &hoge7;
hoge4 = &hoge7;
hoge5 = &hoge7;
PR(hoge2);
PR(hoge4);
PR(hoge5);
}

compile

docker/ubuntu
# gcc const2.c
const2.c: In function 'main':
const2.c:11:25: warning: initialization of 'const int * const' from incompatible pointer type 'int * const*' [-Wincompatible-pointer-types]
   11 | const int * const hoge6=&hoge3;
      |                         ^
const2.c:25:7: warning: assignment to 'const int *' from incompatible pointer type 'int **' [-Wincompatible-pointer-types]
   25 | hoge4 = &hoge2;
      |       ^
const2.c:26:7: warning: assignment to 'const int *' from incompatible pointer type 'int **' [-Wincompatible-pointer-types]
   26 | hoge5 = &hoge2;
      |       ^
const2.c:27:7: warning: assignment to 'const int *' from incompatible pointer type 'int **' [-Wincompatible-pointer-types]
   27 | hoge7 = &hoge2;
      |       ^
const2.c:32:7: warning: assignment to 'int *' from incompatible pointer type 'int * const*' [-Wincompatible-pointer-types]
   32 | hoge2 = &hoge3;
      |       ^
const2.c:33:7: warning: assignment to 'const int *' from incompatible pointer type 'int * const*' [-Wincompatible-pointer-types]
   33 | hoge4 = &hoge3;
      |       ^
const2.c:34:7: warning: assignment to 'const int *' from incompatible pointer type 'int * const*' [-Wincompatible-pointer-types]
   34 | hoge5 = &hoge3;
      |       ^
const2.c:35:7: warning: assignment to 'const int *' from incompatible pointer type 'int * const*' [-Wincompatible-pointer-types]
   35 | hoge7 = &hoge3;
      |       ^
const2.c:40:7: warning: assignment to 'int *' from incompatible pointer type 'const int **' [-Wincompatible-pointer-types]
   40 | hoge2 = &hoge4;
      |       ^
const2.c:41:7: warning: assignment to 'const int *' from incompatible pointer type 'const int **' [-Wincompatible-pointer-types]
   41 | hoge5 = &hoge4;
      |       ^
const2.c:42:7: warning: assignment to 'const int *' from incompatible pointer type 'const int **' [-Wincompatible-pointer-types]
   42 | hoge7 = &hoge4;
      |       ^
const2.c:46:7: warning: assignment to 'int *' from incompatible pointer type 'const int **' [-Wincompatible-pointer-types]
   46 | hoge2 = &hoge5;
      |       ^
const2.c:47:7: warning: assignment to 'const int *' from incompatible pointer type 'const int **' [-Wincompatible-pointer-types]
   47 | hoge4 = &hoge5;
      |       ^
const2.c:48:7: warning: assignment to 'const int *' from incompatible pointer type 'const int **' [-Wincompatible-pointer-types]
   48 | hoge7 = &hoge5;
      |       ^
const2.c:52:7: warning: assignment to 'int *' from incompatible pointer type 'const int * const*' [-Wincompatible-pointer-types]
   52 | hoge2 = &hoge6;
      |       ^
const2.c:53:7: warning: assignment to 'const int *' from incompatible pointer type 'const int * const*' [-Wincompatible-pointer-types]
   53 | hoge4 = &hoge6;
      |       ^
const2.c:54:7: warning: assignment to 'const int *' from incompatible pointer type 'const int * const*' [-Wincompatible-pointer-types]
   54 | hoge5 = &hoge6;
      |       ^
const2.c:55:7: warning: assignment to 'const int *' from incompatible pointer type 'const int * const*' [-Wincompatible-pointer-types]
   55 | hoge7 = &hoge6;
      |       ^
const2.c:60:7: warning: assignment to 'int *' from incompatible pointer type 'const int **' [-Wincompatible-pointer-types]
   60 | hoge2 = &hoge7;
      |       ^
const2.c:61:7: warning: assignment to 'const int *' from incompatible pointer type 'const int **' [-Wincompatible-pointer-types]
   61 | hoge4 = &hoge7;
      |       ^
const2.c:62:7: warning: assignment to 'const int *' from incompatible pointer type 'const int **' [-Wincompatible-pointer-types]
   62 | hoge5 = &hoge7;
      |       ^
const3.c

#include <stdio.h>
#define PR(a) printf("%" #a " = " , a,¥n)

int main(){

int hoge1=1;
int * hoge2;
int * const hoge3=&hoge1;
const int * hoge4;
int const * hoge5;
const int * const hoge6=hoge3;
const int const * hoge7;

hoge2= &hoge1;
hoge4 = &hoge1;
hoge5 = &hoge1;
hoge7 = &hoge1;
PR(hoge1);
PR(hoge2);
PR(hoge3);
PR(hoge4);
PR(hoge5);
PR(hoge6);

hoge4 = hoge2;
hoge5 = hoge2;
hoge7 = hoge2;
PR(hoge4);
PR(hoge5);
PR(hoge7);
hoge2 = hoge3;
hoge4 = hoge3;
hoge5 = hoge3;
hoge7 = hoge3;
PR(hoge2);
PR(hoge4);
PR(hoge5);
PR(hoge7);
hoge2 = hoge4;
hoge5 = hoge4;
hoge7 = hoge4;
PR(hoge2);
PR(hoge5);
PR(hoge7);
hoge2 = hoge5;
hoge4 = hoge5;
hoge7 = hoge5;
PR(hoge2);
PR(hoge4);
PR(hoge7);
hoge2 = hoge6;
hoge4 = hoge6;
hoge5 = hoge6;
hoge7 = hoge6;
PR(hoge3);
PR(hoge4);
PR(hoge5);
PR(hoge6);
hoge2 = hoge7;
hoge4 = hoge7;
hoge5 = hoge7;
PR(hoge2);
PR(hoge4);
PR(hoge5);
}
docker/ubuntu
# gcc const3.c
const3.c: In function 'main':
const3.c:39:7: warning: assignment discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
   39 | hoge2 = hoge4;
      |       ^
const3.c:45:7: warning: assignment discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
   45 | hoge2 = hoge5;
      |       ^
const3.c:51:7: warning: assignment discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
   51 | hoge2 = hoge6;
      |       ^
const3.c:59:7: warning: assignment discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
   59 | hoge2 = hoge7;
      |       ^
const4.c

#include <stdio.h>
#define PR(a) printf( #a " = %d \n',a)

int main(){

int hoge1=1;
int * hoge2;
int * const hoge3=&hoge1;
const int * hoge4;
int const * hoge5;
const int * const hoge6=hoge3;
const int const * hoge7;

hoge2= &hoge1;
hoge4 = &hoge1;
hoge5 = &hoge1;
hoge7 = &hoge1;
PR(hoge1);
PR(hoge2);
PR(hoge3);
PR(hoge4);
PR(hoge5);
PR(hoge6);

hoge4 = hoge2;
hoge5 = hoge2;
hoge7 = hoge2;
PR(hoge4);
PR(hoge5);
PR(hoge7);
hoge2 = hoge3;
hoge4 = hoge3;
hoge5 = hoge3;
hoge7 = hoge3;
PR(hoge2);
PR(hoge4);
PR(hoge5);
PR(hoge7);
hoge2 = hoge4;
hoge5 = hoge4;
hoge7 = hoge4;
PR(hoge2);
PR(hoge5);
PR(hoge7);
hoge2 = hoge5;
hoge4 = hoge5;
hoge7 = hoge5;
PR(hoge2);
PR(hoge4);
PR(hoge7);
hoge2 = hoge6;
hoge4 = hoge6;
hoge5 = hoge6;
hoge7 = hoge6;
PR(hoge3);
PR(hoge4);
PR(hoge5);
PR(hoge6);
hoge2 = hoge7;
hoge4 = hoge7;
hoge5 = hoge7;
PR(hoge2);
PR(hoge4);
PR(hoge5);
}
docker/ubuntu
# gcc const4.c
const3.c: In function 'main':
const3.c:39:7: warning: assignment discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
   39 | hoge2 = hoge4;
      |       ^
const3.c:45:7: warning: assignment discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
   45 | hoge2 = hoge5;
      |       ^
const3.c:51:7: warning: assignment discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
   51 | hoge2 = hoge6;
      |       ^
const3.c:59:7: warning: assignment discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
   59 | hoge2 = hoge7;
      |       ^
root@b3af5df58ca0:/# ./a.out
hoge1 = 1 
hoge2 = 674864636 
hoge3 = 674864636 
hoge4 = 674864636 
hoge5 = 674864636 
hoge6 = 674864636 
hoge4 = 674864636 
hoge5 = 674864636 
hoge7 = 674864636 
hoge2 = 674864636 
hoge4 = 674864636 
hoge5 = 674864636 
hoge7 = 674864636 
hoge2 = 674864636 
hoge5 = 674864636 
hoge7 = 674864636 
hoge2 = 674864636 
hoge4 = 674864636 
hoge7 = 674864636 
hoge3 = 674864636 
hoge4 = 674864636 
hoge5 = 674864636 
hoge6 = 674864636 
hoge2 = 674864636 
hoge4 = 674864636 
hoge5 = 674864636
const5.c
#include <stdio.h>
#define PR(a) printf( #a " = %d \n',a)

int main(){

int hoge1=1;
int * hoge2;
int * const hoge3=&hoge1;
const int * hoge4;
int const * hoge5;
const int * const hoge6=hoge3-2;
const int const * hoge7;

hoge2= &hoge1-1;
hoge4 = &hoge1+1;
hoge5 = &hoge1+2;
hoge7 = &hoge1+3;
PR(hoge1);
PR(hoge2);
PR(hoge3);
PR(hoge4);
PR(hoge5);
PR(hoge6);

hoge4 = hoge2;
hoge5 = hoge2;
hoge7 = hoge2;
PR(hoge4);
PR(hoge5);
PR(hoge7);
hoge2 = hoge3;
hoge4 = hoge3;
hoge5 = hoge3;
hoge7 = hoge3;
PR(hoge2);
PR(hoge4);
PR(hoge5);
PR(hoge7);
hoge2 = hoge4;
hoge5 = hoge4;
hoge7 = hoge4;
PR(hoge2);
PR(hoge5);
PR(hoge7);
hoge2 = hoge5;
hoge4 = hoge5;
hoge7 = hoge5;
PR(hoge2);
PR(hoge4);
PR(hoge7);
hoge2 = hoge6;
hoge4 = hoge6;
hoge5 = hoge6;
hoge7 = hoge6;
PR(hoge3);
PR(hoge4);
PR(hoge5);
PR(hoge6);
hoge2 = hoge7;
hoge4 = hoge7;
hoge5 = hoge7;
PR(hoge2);
PR(hoge4);
PR(hoge5);
}
docker/ubuntu
# gcc const5.c
const5.c: In function 'main':
const5.c:39:7: warning: assignment discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
   39 | hoge2 = hoge4;
      |       ^
const5.c:45:7: warning: assignment discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
   45 | hoge2 = hoge5;
      |       ^
const5.c:51:7: warning: assignment discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
   51 | hoge2 = hoge6;
      |       ^
const5.c:59:7: warning: assignment discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
   59 | hoge2 = hoge7;
      |       ^
root@b3af5df58ca0:/# ./a.out
hoge1 = 1 
hoge2 = -1928507144 
hoge3 = -1928507140 
hoge4 = -1928507136 
hoge5 = -1928507132 
hoge6 = -1928507148 
hoge4 = -1928507144 
hoge5 = -1928507144 
hoge7 = -1928507144 
hoge2 = -1928507140 
hoge4 = -1928507140 
hoge5 = -1928507140 
hoge7 = -1928507140 
hoge2 = -1928507140 
hoge5 = -1928507140 
hoge7 = -1928507140 
hoge2 = -1928507140 
hoge4 = -1928507140 
hoge7 = -1928507140 
hoge3 = -1928507140 
hoge4 = -1928507148 
hoge5 = -1928507148 
hoge6 = -1928507148 
hoge2 = -1928507148 
hoge4 = -1928507148 
hoge5 = -1928507148 
const7.c
#include <stdio.h>
#define PR(a) printf( #a " = %d \n",a)

int main(){

int hoge1=1;
int * hoge2;
int * const hoge3=&hoge1;
const int * hoge4;
int const * hoge5;
const int * const hoge6=hoge3-2;
const int const * hoge7;

hoge2= &hoge1-1;
hoge4 = &hoge1+1;
hoge5 = &hoge1+2;
hoge7 = &hoge1+3;
PR(hoge1);
PR(hoge2);
PR(hoge3);
PR(hoge4);
PR(hoge5);
PR(hoge6);
PR(hoge7);
PR(*hoge2);
PR(*hoge3);
PR(*hoge4);
PR(*hoge5);
PR(*hoge6);
PR(*hoge7);
hoge4 = hoge2;
hoge5 = hoge2;
hoge7 = hoge2;
PR(hoge4);
PR(hoge5);
PR(hoge7);
PR(*hoge4);
PR(*hoge5);
PR(*hoge7);
hoge2 = hoge3;
hoge4 = hoge3;
hoge5 = hoge3;
hoge7 = hoge3;
PR(hoge2);
PR(hoge4);
PR(hoge5);
PR(hoge7);
PR(*hoge2);
PR(*hoge4);
PR(*hoge5);
PR(*hoge7);
hoge2 = hoge4;
hoge5 = hoge4;
hoge7 = hoge4;
PR(hoge2);
PR(hoge5);
PR(hoge7);
PR(*hoge2);
PR(*hoge5);
PR(*hoge7);
hoge2 = hoge5;
hoge4 = hoge5;
hoge7 = hoge5;
PR(hoge2);
PR(hoge4);
PR(hoge7);
PR(*hoge2);
PR(*hoge4);
PR(*hoge7);
hoge2 = hoge6;
hoge4 = hoge6;
hoge5 = hoge6;
hoge7 = hoge6;
PR(hoge3);
PR(hoge4);
PR(hoge5);
PR(hoge6);
PR(*hoge3);
PR(*hoge4);
PR(*hoge5);
PR(*hoge7);
hoge2 = hoge7;
hoge4 = hoge7;
hoge5 = hoge7;
PR(hoge2);
PR(hoge4);
PR(hoge5);
PR(*hoge2);
PR(*hoge4);
PR(*hoge5);
}
docker/ubuntu
# gcc const7.c
const7.c: In function 'main':
const7.c:52:7: warning: assignment discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
   52 | hoge2 = hoge4;
      |       ^
const7.c:61:7: warning: assignment discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
   61 | hoge2 = hoge5;
      |       ^
const7.c:70:7: warning: assignment discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
   70 | hoge2 = hoge6;
      |       ^
const7.c:82:7: warning: assignment discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
   82 | hoge2 = hoge7;
      |       ^
root@b3af5df58ca0:/# ./c.out
bash: ./c.out: No such file or directory
root@b3af5df58ca0:/# ./a.out
hoge1 = 1 
hoge2 = 1240014920 
hoge3 = 1240014924 
hoge4 = 1240014928 
hoge5 = 1240014932 
hoge6 = 1240014916 
hoge7 = 1240014936 
*hoge2 = 4200213 
*hoge3 = 1 
*hoge4 = 1240014936 
*hoge5 = 32767 
*hoge6 = 0 
*hoge7 = 1240014932 
hoge4 = 1240014920 
hoge5 = 1240014920 
hoge7 = 1240014920 
*hoge4 = 4200213 
*hoge5 = 4200213 
*hoge7 = 4200213 
hoge2 = 1240014924 
hoge4 = 1240014924 
hoge5 = 1240014924 
hoge7 = 1240014924 
*hoge2 = 1 
*hoge4 = 1 
*hoge5 = 1 
*hoge7 = 1 
hoge2 = 1240014924 
hoge5 = 1240014924 
hoge7 = 1240014924 
*hoge2 = 1 
*hoge5 = 1 
*hoge7 = 1 
hoge2 = 1240014924 
hoge4 = 1240014924 
hoge7 = 1240014924 
*hoge2 = 1 
*hoge4 = 1 
*hoge7 = 1 
hoge3 = 1240014924 
hoge4 = 1240014916 
hoge5 = 1240014916 
hoge6 = 1240014916 
*hoge3 = 1 
*hoge4 = 0 
*hoge5 = 0 
*hoge7 = 0 
hoge2 = 1240014916 
hoge4 = 1240014916 
hoge5 = 1240014916 
*hoge2 = 0 
*hoge4 = 0 
*hoge5 = 0 
const7.cpp
#include <stdio.h>
#define PR(a) printf( #a " = %d \n",a)

int main(){

int hoge1=1;
int * hoge2;
int * const hoge3=&hoge1;
const int * hoge4;
int const * hoge5;
const int * const hoge6=hoge3-2;
const int const * hoge7;

hoge2= &hoge1-1;
hoge4 = &hoge1+1;
hoge5 = &hoge1+2;
hoge7 = &hoge1+3;
PR(hoge1);
PR(hoge2);
PR(hoge3);
PR(hoge4);
PR(hoge5);
PR(hoge6);
PR(hoge7);
PR(*hoge2);
PR(*hoge3);
PR(*hoge4);
PR(*hoge5);
PR(*hoge6);
PR(*hoge7);
hoge4 = hoge2;
hoge5 = hoge2;
hoge7 = hoge2;
PR(hoge4);
PR(hoge5);
PR(hoge7);
PR(*hoge4);
PR(*hoge5);
PR(*hoge7);
hoge2 = hoge3;
hoge4 = hoge3;
hoge5 = hoge3;
hoge7 = hoge3;
PR(hoge2);
PR(hoge4);
PR(hoge5);
PR(hoge7);
PR(*hoge2);
PR(*hoge4);
PR(*hoge5);
PR(*hoge7);
hoge2 = hoge4;
hoge5 = hoge4;
hoge7 = hoge4;
PR(hoge2);
PR(hoge5);
PR(hoge7);
PR(*hoge2);
PR(*hoge5);
PR(*hoge7);
hoge2 = hoge5;
hoge4 = hoge5;
hoge7 = hoge5;
PR(hoge2);
PR(hoge4);
PR(hoge7);
PR(*hoge2);
PR(*hoge4);
PR(*hoge7);
hoge2 = hoge6;
hoge4 = hoge6;
hoge5 = hoge6;
hoge7 = hoge6;
PR(hoge3);
PR(hoge4);
PR(hoge5);
PR(hoge6);
PR(*hoge3);
PR(*hoge4);
PR(*hoge5);
PR(*hoge7);
hoge2 = hoge7;
hoge4 = hoge7;
hoge5 = hoge7;
PR(hoge2);
PR(hoge4);
PR(hoge5);
PR(*hoge2);
PR(*hoge4);
PR(*hoge5);
}
# g++ const7.cpp
const7.cpp: In function 'int main()':
const7.cpp:12:11: error: duplicate 'const'
   12 | const int const * hoge7;
      |           ^~~~~
      |           -----
const7.cpp:52:9: error: invalid conversion from 'const int*' to 'int*' [-fpermissive]
   52 | hoge2 = hoge4;
      |         ^~~~~
      |         |
      |         const int*
const7.cpp:61:9: error: invalid conversion from 'const int*' to 'int*' [-fpermissive]
   61 | hoge2 = hoge5;
      |         ^~~~~
      |         |
      |         const int*
const7.cpp:70:9: error: invalid conversion from 'const int*' to 'int*' [-fpermissive]
   70 | hoge2 = hoge6;
      |         ^~~~~
      |         |
      |         const int*
const7.cpp:82:9: error: invalid conversion from 'const int*' to 'int*' [-fpermissive]
   82 | hoge2 = hoge7;
      |         ^~~~~
      |         |
      |         const int*
const8.cpp:44:7: error: assignment of read-only variable 'hoge3'
   44 | hoge3 = hoge4;
      | ~~~~~~^~~~~~~
const8.cpp:50:7: error: assignment of read-only variable 'hoge3'
   50 | hoge3 = hoge5;
      | ~~~~~~^~~~~~~
const8.cpp:56:7: error: assignment of read-only variable 'hoge3'
   56 | hoge3 = hoge6;
      | ~~~~~~^~~~~~~
#include <stdio.h>
#define PR(a) printf( #a " = %d \n",a)

int main(){

int hoge1=1;
int * hoge2;
int * const hoge3=&hoge1;
const int * hoge4;
int const * hoge5;
const int * const hoge6=hoge3-2;
//const int const * hoge7;

hoge2= &hoge1-1;
hoge4 = &hoge1+1;
hoge5 = &hoge1+2;
//hoge7 = &hoge1+3;
PR(hoge1);
PR(hoge2);
PR(hoge3);
PR(hoge4);
PR(hoge5);
PR(hoge6);
PR(*hoge2);
PR(*hoge3);
PR(*hoge4);
PR(*hoge5);
PR(*hoge6);
hoge4 = hoge2;
hoge5 = hoge2;
PR(hoge4);
PR(hoge5);
PR(*hoge4);
PR(*hoge5);
hoge2 = hoge3;
hoge4 = hoge3;
hoge5 = hoge3;
PR(hoge2);
PR(hoge4);
PR(hoge5);
PR(*hoge2);
PR(*hoge4);
PR(*hoge5);
hoge5 = hoge4;
PR(hoge5);
PR(*hoge5);
hoge4 = hoge5;
PR(hoge4);
PR(*hoge4);
hoge4 = hoge6;
hoge5 = hoge6;
PR(hoge4);
PR(hoge5);
PR(hoge6);
PR(*hoge4);
PR(*hoge5);
}
# g++ const9.cpp
# ./a.out
hoge1 = 1 
hoge2 = 1182859008 
hoge3 = 1182859012 
hoge4 = 1182859016 
hoge5 = 1182859020 
hoge6 = 1182859004 
*hoge2 = 1585718576 
*hoge3 = 1 
*hoge4 = 1182859020 
*hoge5 = 32766 
*hoge6 = 0 
hoge4 = 1182859008 
hoge5 = 1182859008 
*hoge4 = 1585718576 
*hoge5 = 1585718576 
hoge2 = 1182859012 
hoge4 = 1182859012 
hoge5 = 1182859012 
*hoge2 = 1 
*hoge4 = 1 
*hoge5 = 1 
hoge5 = 1182859012 
*hoge5 = 1 
hoge4 = 1182859012 
*hoge4 = 1 
hoge4 = 1182859004 
hoge5 = 1182859004 
hoge6 = 1182859004 
*hoge4 = 0 
*hoge5 = 0 

#docker起動方法

$ docker run -it kaizenjapan/constc /bin/bash

最後までおよみいただきありがとうございました。

いいね 💚、フォローをお願いします。

Thank you very much for reading to the last sentence.

Please press the like icon 💚 and follow me for your happy life.

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?