[CTAP] 5# Library Functions

문연수·2022년 8월 19일
0

CTAP

목록 보기
6/9
post-thumbnail

 Perhaps the best piece of advice about using library functions is to use system header files whenever possible.

1. Words

  • Plain:
    1. (보거나 이해하기에) 분명한
    2. 숨김없는, 솔직한, 있는 그대로의
    3. 소박한, 꾸미지 않은
    4. 무늬[표시]가 없는, 무지의
    5. (강조의 의미로 쓰여) 보통의[평범한]
    6. (특히 여성이) 아름답지 않은, 매력없는
    7. (뜨개질에서) 겉뜨기의
  • Silly:
    1. 어리석은
    2. 바보
    3. 우스꽝스러운, 유치한, 철이 없는
  • wherever:
    1. 어디에나, 어디든지
    2. (...한 곳) 어디에나 [모든 곳에] (= everywhere)
    3. (놀람을 나타내어) 도대체 어디에서 [어디로]
  • assure:
    1. 장담하다, 확언[확약]하다
    2. (~임을) 보장하다.
    3. 보장하다 (= guarantee)
  • legitimate:
    1. 정당한, 타당한, 적당한 (= valid, justifiable)
    2. 합법적인, 적법한 (= legal)
  • take on:
    1. (일 등을) 맡다, (책임을) 지다.
    2. 태우다, 싣다.
  • intervening: (두 사건, 날짜, 사물 등의) 사이에 오는 [있는]
  • subtly:
    1. 미묘한, 감지하기 힘든
    2. 교묘한, 영리한
    3. 절묘한
  • thence: (옛 글투 또는 격식) 거기에서, 그 뒤에
  • vested:
    1. (법) (권리 등의) 소유가 확정된, 기득의
    2. 확립된, 보호받는, 기정의
    3. 제복을 입는
  • henceforth (henceforward): (격식) ...이후로 (죽)
  • subtle:
    1. (흔히 호감) 미묘한, 감지하기 힘든
    2. 교묘한, 영리한
    3. 절묘한.
  • sleazy:
    1. (특히 섹스가 개입된) 지저분한[추잡한] (= disreputable)
    2. (행실이) 지저분한[추잡한]
  • obligation: (법적, 도의적) 의무(가 있음), 의무 (마땅히 해야 할 일) (= commitment)
  • oblige:
    1. 의무적으로[부득이] ...하게 하다.
    2. 돕다, (도움 등을) 베풀다.
  • absense:
    1. 결석, 결근, 부재
    2. 없음, 결핍
  • obliterate: (흔적을) 없애다[지우다]
  • presence:
    1. (특정한 곳에) 있음, 존재 (함), 참석
    2. 있음
    3. (특정 상황을 처리하기 위해) 주둔하는 사람들, 주둔군
  • mayhem: 대혼란, 아수라장
  • assumption:
    1. 추정, 상정
    2. (권력 책임의) 인수[장악]
  • intrinsically: 본질적으로

2. Summery

- 1. getchar() returns an integer.

#include <stdio.h>

main()
{
	char c;
    
	while ((c = getchar()) != EOF)
    	putchar(c);
}

 The reason is that c is declared as a character rather than as an integer. This means that it is impossible for c to hold every possible character as well as EOF.

- 2. Updating a sequantial file

FILE *fp;
fp = fopen(file, "r+");

 Once this has been done, one would think it should be possible to intermix read and write operations freely. Unfortunately, because of efforts to maintain compatibility with programs written before this option became available, this is not so: an input options may never directly follow an output operation or vice versa without an intervening call to fseek()

FILE *fp;
struct record rec;

while (fread((char *)&rec, sizeof(rec), 1, fp) == 1) {
	/* do something to rec */
    if (rec must be re-written) {
    	fseek(fp, -(long) sizeof(rec), 1);
        fwrite((char *) &rec, sizeof(rec), 1, fp);
        fseek(fp, 0L, 1); /* do nothing, but needed */
    }
}

 과거에 이런 일이 있었다고 하네요... 인터레스팅...

- 3. Buffered output and memory allocation.

#include <stdio.h>
main() {
	int c;
    char buf[BUFSIZ];
    setbuf(stdout, buf);
    while ((c = getchar()) != EOF)
    	putchar(c);
}

 Unfortunately, this program is wrong, for a subtle reason. The call to setbuf() asks the I/O library to use the buffer buf to hold characters on their way to the trouble lies, ask when buf is flushed for the last time. Answer: after the main program has finished, as part of the cleaning up that the library does before handling control back to the operationg system. But by the time, buf has already been freed!

- 4. Using errno for error detection

 Thus when calling a library function, it is essential to tset the value it returns for an error indication before examing errno to find the cause of the error:

call library function
if (error return)
	examine errno

- 5. The signal() function

 Thus it is not safe for a signal handler function to call any such library function . Thus the only portable, reasonably safe thing a signal handler for an arithmatic error can do is to print a message and exit (by using either longjmp() or exit())

 The best defense against problems is to keep signal handlers as simple as possible and group them all together.

3. Exercise

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

4. References

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

profile
2000.11.30

0개의 댓글