[CTAP] 2# Syntactical Pitfalls

문연수·2022년 8월 2일
0

CTAP

목록 보기
3/9
post-thumbnail

0. Terminologies

  • A list of expression-like things called declarators. A declarator looks something like on expression that is expected to evaluate to the given type.
  • Sequential operator: Operator that have the sequence point. (필자의 추측임)
  • delimiter: Something such as a mark or symbol used to show the begginning or end of separate elements in a text, computer program, etc.

1. Words

  • Counter-intuitive: 직관적이지 않은.
  • devise: 궁리하다, 고안하다, 안출하다, 유증하다.
    - 유증, 부동산 유증
    - 안출(책상 안, 날 출)하다: 생각해내다.
    - 유증하다: 물건을 보내다. 유언에 의하여 유산의 전부 또는 일부를 무상으로 다른 사람에게 물려주다.
    - to invent a plan, system, object, etc., usually using your intelligence or imagination.
  • strike terror, strike fear into someone: to make someone extremely frightened. 공포에 떨게 하다?
  • analogously: 비슷하게
  • analogous: having similar features to another thing and therefore able to be compared with it, 유사한.
  • intuitive: 직관적인
  • insist: to sya firmly or demand forcefully, especially when others disagree with or oppose what you say., 주장하다.
  • tackle: to try to deal with something or someone. 씨름하다.
  • messy: untidy, 지저분한, 엉망인 (= chaotic), 지저분하게 만드는, 골치 아픈
  • relative: 비교상의, 상대적인, ~과 관련지은, ~에 따라서 본
    - 친척 (= relation), 동족, 동류.
  • hypothetical: imagined or suggested but, not necessarily real or true. 가상적인, 가설[가정]의
  • suggest: 제안하다, 암시하다.
  • unimpeded: not stopped, or prevented by anything, 가로막는 것이 없는, 방해받지 않는.
  • predecessor: someone who had a job or a position before someone else, or something that comes before another thing in time or in a series., 전임자, 이전 것[모델]
  • deem: to consider or judge something in a particular way. (~으로) 여기다[생각하다] (= consider)
  • elicit: to get or produce something, especially information or a reaction. (정보, 반응을 어렵게) 끌어내다.
  • morbid: too interested in unpleasant subjects, especially death. (특히 질병, 죽음에 대한 관심이) 병적인 [소름끼치는]
  • readily: quickly, immediately, willingly, or without any problem. 손쉽게, 순조롭게 (= freely), 선뜻, 기꺼이(= willing)
  • deliberately: intentionally, 고의로, 의도[계획]적으로.
  • leave out: to not include someone or something. 빼다, 생략하다, 무시하다.
  • steep: (of a slope) rising or falling at a sharp angle. 가파른, 비탈진, 급격한 (= sharp)
  • steep something/someone in something: If something or someone is steep in something, they are completely surrounded by or involved in it, or know a lot about it. ~에 푹 빠져 지내다.
  • speculate: to guess possible answers to a question when you do not have enough information to be certain., 추측[짐작]하다, 투기하다.

2. Summery

- 1. Understanding function declarations

(*(void(*)())0)();

 Cast 0 as the pointer of the function and called it.

 If fp is a pointer to a function, *fp is the function itself, so (*fp)() is the way to invoke it. ANSI C permits this to be abbreviated as fp(), but keep in mind that it is only an abbreviation.

- 2. Operators don't always have the precedence you want

operatorassociativity
() [] -> .left
! ~ ++ -- - (type) * & sizeofright
* / %left
+ -left
<< >>left
< <= > >=left
== !=left
&left
^left
\|left
&&left
\|\|left
?:right
assignmentsright
,left

The two most important things to keep in mind are:

  1. Every logical operator has lower precedence than every relational operator.
  2. The shift operators bind more tightly than the relational operators but less tightly than the arithmetic operators.

The precedence of these operators comes about for historical reasons. B, the predecessor of C, had logical operators that corresponded roughly to C's & and | operators. Although they were defined to act on bits, the compiler would treat them as the present && and || operators if they were used in a conditional context.

- 3. Watch those semicolons!

 An extra semicolon in a C program may be harmless: it might be a null statement, which has no effect, or it might elicit a diagnostic message from the compiler, which makes it easy to remove. One important exception is after an if or while clause, which must be followed by exactly one statement.

- 4. The switch statement

 It is a weakness because leaving out a break statement is easy and often gives rise to obscure program misbehavior. It is a strength because by leaving out a break statement deliberately, one can readily express a control structure that is inconveenient to implement otherwise.

- 5. Calling functions

/* Calling function `f` */
f();
/* Evaluate the pointer value of the function `f`, then discard it. (Doesn't called) */
f;

- 6. The dangling else problem

if (x == 0)
	if (y == 0) error();
else {
	z = x + y;
    f(&z);
}

is equal to:

if (x == 0) {
	if (y == 0)
    	error();
	else {
    	z = x + y;
        f(&z);
    }
}

3. Exercises

https://www.mythos-git.com/Cruzer-S/CTAP/-/tree/main/Chapter02

4. References

[Book] C Traps and Pitfalls (Andrew Koenig)
[Site] Cambridge Dictionary
[Site] 네이버 영영, 영한사전

profile
2000.11.30

0개의 댓글