が私のコードを見た値動作を停止:Cプログラムは、いくつかのアドレスを変更すると
#include <stdio.h>
#include <limits.h>
int main (int argc, const char *argv[]) {
typedef unsigned char byte;
byte *pointer;
byte b1=1;
byte b2=2;
int i1 =4;
int i2 =0x12345678;
byte b3=5;
byte b4=6;
byte b5=7;
byte b6=9;
//pointer = &b6;
pointer = (byte*)&i2;
printf("pointer has value %p\n", pointer);
printf("the byte it points to contains %x\n", *pointer);
pointer = pointer + 1;
printf("the byte it points to contains %x\n", *pointer);
pointer = pointer + 1;
printf("the byte it points to contains %x\n", *pointer);
pointer = pointer + 1;
printf("the byte it points to contains %x\n", *pointer);
pointer = pointer + 1;
printf("the byte it points to contains %x\n", *pointer);
pointer = pointer + 1;
printf("the byte it points to contains %x\n", *pointer);
pointer = pointer + 1;
printf("the byte it points to contains %x\n", *pointer);
pointer = pointer + 1;
printf("the byte it points to contains %x\n", *pointer);
pointer = pointer + 1;
printf("the byte it points to contains %x\n", *pointer);
pointer = pointer + 1;
printf("the byte it points to contains %x\n", *pointer);
pointer = pointer + 1;
printf("the byte it points to contains %x\n", *pointer);
pointer = pointer + 1;
printf("the byte it points to contains %x\n", *pointer);
pointer = pointer + 1;
*pointer = 255;
printf("the byte it points to contains %x\n", *pointer);
pointer = pointer + 1;
*pointer = 45;
printf("the byte it points to contains %x\n", *pointer);
pointer = pointer + 1;
*pointer = 34;
printf("the byte it points to contains %x\n", *pointer);
//printf("How big is int in this machine? %d\n", INT_MAX);
//insert code here ...
printf (" b1 (%p) = %x\n", &b1, b1);
printf (" b2 (%p) = %x\n", &b2, b2);
printf (" i1 (%p) = %d\n", &i1, i1);
printf (" i2 (%p) = %x\n", &i2, i2);
printf (" b3 (%p) = %x\n", &b3, b3);
printf (" b4 (%p) = %x\n", &b4, b4);
printf (" b5 (%p) = %x\n", &b5, b5);
printf (" b6 (%p) = %x\n", &b6, b6);
return 0;
}
言っライン*ポインタ= 255;同様に、この if I make , *pointer = 255 or *pointer = 254
または他の任意の値の場合を言っ、多分40行、コンパイラが吹く、またはコードは動作を停止し、それはどんな打撃なしで実行されます。このアドレスの動作について教えてください。
出典:Richard Buckland教授、私は彼のガイダンスのためにこれらのすべてを検討しています。
あなたのコンパイラは爆破されませんでした。あなたのコンパイラはうまくいきます。あなたのプログラムは悪いです。 – Art
あなたは 'pointer'値をあなたがダメージを与えるアドレスに移動しています。未定義の動作。 –
よろしくお願いします。#ワインと#アート!私は、どのようにメモリが使用されているか、変数がどこに格納されているかを調べようとしていました。だから、変数_int i1_がプログラムに格納されていたアドレスの直下だったので、その場所に正確に何が格納されているか教えてください。フレームポインタのアドレスかクリティカルセクションですか? –