본문 바로가기
대학강의정리/기타

컴파일러.how c++ handle semantic errors

by 피스타0204 2025. 2. 3.

char n1, n2
n3=n1*n2;

today, I'm gonna talk about semantic errors(In abstracted way) in c++.

//...
char n1, n2
n3=n1*n2;
n3= n1+n2;



what happens when you compile this code in c++ compiler? is  this code runnable?

you may expect 2 kinds of result. in first situation, it can occurs compile error that means it cannot be run and returns error message to programmer. it is quite convincing because it is very practical in common sense that character types can't deal with plus or mutiply operations.
second situation is more flexible. in this way, it can run but the programmer receives runtime error message.
which is the correct answer?

in c++, character type literals consider as int type. so if you execute char operation, you will get number results.(this relates to ASCII code)


so, in conclusion, c++ didn't consider character operator as a compile error.
this expands to the concept c++ didn't catch semantic errors( I didn't inspect and verify this one but normally it's right).

c++ is a flexible language.

'대학강의정리 > 기타' 카테고리의 다른 글

기계학습_chap0. 머신러닝이란  (0) 2024.04.07