You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
```c
int main(void)
{
volatile char A[10] = "string";
volatile char *B = "string";
// 차이점 : 사이즈,
// A[10]은 원본 수정하지 x, 복사해서 사용하는 것
// *B는 원본을 수정할 수 있어
A[1] = 'a';
B[1] = 'a';
*(A+1) = 'a';
*(B+1) = 'a';
return 0;
}
```
위의 코드에서 trap 빠진 상태
Little endian Vs Big Endian
우선순위
short*(*(*var)())[5]
배열에는 함수와 void를 담을 수 없다.
return 은 short ()[]
char 형태의 불안정
레지스터는 signed라고 생각한다.
포인터 타입은 더하기 빼기는 되지만 나머지는 안된다.
데이터 타입 변환
char
short
signed int
unsigned int
float
double
long double
큰 쪽으로 형변환
int보다 작은 char와 short는 다르다!!
volatileunsigned intA=-1;
volatilesigned intB=1;
volatileinttmp=0;
// if(0xffffffff > 0x00000001)// unsigned와 signed는 인코딩이 달라!!// 다른 타입이 되어야하는데 위에 true로 하려면// signed가 unsigned가 되어야 1이 된다.// int보다 작은거는 int로 변환// char + short -> 각 각 int로 변환되서 연산!! // int + float -> int가 float로 변환되서 연산(컴퓨터마다 달라)// float + double -> float가 double로 변환 if(A>B)
{
tmp=1;
}
else
{
tmp=2;
}
데이터 타입
데이터 타입은 양쪽에 다 있다(왼쪽에만 잇지 x)
int arr[2][3]
arr : int [2][3]
&arr[0] : int (*)[3]
형변환이 일어난 것
즉 int (*A)[3]으로 만들어야...?
arr[0] : int [3]
int A;
A : int
&A : int (*)
()는 우선순위를 뜻한다.
이런 문법을 거의 본적 없는 이유
가려진다.
typedefint (*ID)[3];
// typedef를 사용하면 ID var 이런식으로 사용할 수 있어.typedefintARR[2][3];
// ARR var1
pointers
이 타입을 받을 수 있는 포인터 타입
intA[5]; // int (*p);intA[2][3]; // int (*p)[3];int*A[5]; // int *(*p);, int **p;void (*A[256])(void); // void (*(*p))(void) = A;// A[] -> (*p) 로만 변환하면 ok
구조체의 주소를 매개변수로 넘겨줄 때
/***************************************************** * * myproject.c * * Description : Hello World in C, ANSI-style * */voidfunc(int*arg)
{
/* // a -> 'A' volatile char a = (*(struct va_tag *)arg).a; // b -> 10 volatile short b = (*(struct va_tag *)arg).b; // c -> 500 volatile int c = (*(struct va_tag *)arg).c; // d -> 1000 volatile long d = (*(struct va_tag *)arg).d; // e -> 3.14 volatile float e = (*(struct va_tag *)arg).e; // f -> 6.625 volatile double f = (*(struct va_tag *)arg).f; // *P -> 123 volatile int * p = (*(struct va_tag *)arg).p; volatile int tmp = *p; p = ((struct va_tag *)arg)->p;*/// a -> 'A'volatilechara=*((char*)arg+0);
// b -> 10volatileshortb=*(short*)((char*)arg+2);
// c -> 500volatileintc=*(int*)((char*)arg+4);
// d -> 1000volatilelongd=*(long*)((char*)arg+8);
// e -> 3.14volatilefloate=*(float*)((char*)arg+12);
// f -> 6.625volatiledoublef=*(double*)((char*)arg+16);
// *P -> 123volatileint*p=*(int**)((char*)arg+20);
// (*). ==// p = (*).;// (struct va_tag *)arg->p;// arg : 피연산자// -> 연산 순위가 제일 높아// int * -> 는 할 수 없어// arg를 구조체라고 형변환을 시켜주고// p = ((struct va_tag *)arg)->p;// p = (*(struct va_tag *)arg).p;
}
typedefshort*SSI;
typedefSSI (*AP)[3];
typedefAP (*FP)(void);
// 4short*(*(*var)(void))[3];
// 3SSI (*(*var)(void))[3];
// 2//AP (*FP)(void);를 FP를 아래의 내용으로 치환AP (*var)(void);
// 1FPvar;
structva_tag
{
chara;
shortb;
intc;
longd;
floate;
doublef;
int*p;
};
intmain(void)
{
intstart=123;
structva_tagvar= {'A', 10, 500, 1000, 3.14f, 6.625, &start};
func(&var);
}