30.10.2014 Views

o_195h4n6al16jb186b1b2qs7fgssa.pdf

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

{<br />

/* Override default with user defined function */<br />

signal(SIGINT, mysigint);<br />

raise(SIGINT);<br />

/* Ignore signal handler */<br />

signal(SIGILL, SIG_IGN);<br />

raise(SIGILL);<br />

printf("SIGILL was ignored\n");<br />

/* Use default signal handler */<br />

raise(SIGFPE);<br />

printf("Program never reaches here.");<br />

}<br />

Output:<br />

SIGINT received<br />

SIGILL was ignored<br />

FPE<br />

Explanation:<br />

The function mysigintis the user-defined signal handler for SIGINT.<br />

Inside the main program, the function signalis called to set up the<br />

signal handler (mysigint) for the signal SIGINTthat will override the<br />

default actions. The function raiseis called to report the signal<br />

SIGINT. This causes the signal handler for SIGINTto use the<br />

user-defined function (mysigint) as the signal handler so it prints the<br />

"SIGINT received" message.<br />

Next, the function signalis called to set up the signal handler<br />

SIG_IGNfor the signal SIGILL. The constant SIG_IGNis used to<br />

indicate the signal shouldbe ignored. The function raiseis called to<br />

report the signal SIGILLthat is ignored.<br />

The function raiseis called again to report the signal SIGFPE. Since<br />

there is no user defined function for SIGFPE, the default signal handler<br />

is used so the message "FPE" is printed (which stands for<br />

"arithmetic error - terminating”.) Then the calling program is<br />

terminated. The printfstatement is never reached.<br />

Standard C Libraries with Math Functions<br />

2004 Microchip Technology Inc. DS51456B-page 221<br />

4.11 VARIABLE ARGUMENT LISTS<br />

The header file stdarg.hsupports functions with variable argument lists. This<br />

allows<br />

functions to have arguments without corresponding parameter declarations.<br />

There<br />

khi tới<br />

va_start. Trong MPLAB C30, va_enddoes gì, vì vậy cuộc gọi này không phải là<br />

cần thiết, nhưng nên được sử dụng để có thể đọc và tính di động.<br />

Ví dụ: Xem va_arg.<br />

va_start<br />

Mô tả: Thiết lập con trỏ luận APTO đối số tùy chọn đầu tiên trong<br />

danh sách đối số chiều dài thay đổi<br />

Bao gồm:<br />

Prototype: va_start # define (va_list ap, last_arg)<br />

Đối số: ap con trỏ đến danh sách các đối số<br />

last_arg tên đối số cuối cùng trước khi các đối số tùy chọn<br />

Ví dụ: Xem va_arg.<br />

ptrdiff_t<br />

Mô tả: Các loại kết quả ofsubtracting hai con trỏ.<br />

Bao gồm:<br />

size_t<br />

Mô tả: Các loại kết quả của sizeofoperator.<br />

Bao gồm:<br />

wchar_t<br />

Mô tả: Một loại chứa một giá trị nhân vật rộng.<br />

Bao gồm:<br />

NULL<br />

Mô tả: Giá trị của một con trỏ hằng null.<br />

Bao gồm:<br />

dsPIC<br />

®<br />

Thư viện Công cụ Ngôn ngữ<br />

DS51456B trang 224<br />

offsetof<br />

2004 Microchip Technology Inc<br />

Mô tả: Cung cấp cho bù đắp của một thành viên cơ cấu từ đầu<br />

cấu trúc.<br />

Bao gồm:<br />

Prototype: # define offsetof (T, MBR)<br />

Đối số: tname cấu trúc<br />

MBR tên của thành viên trong cấu trúc T<br />

Quay trở lại giá trị: Trả về bù đắp bằng byte của các thành viên được chỉ định<br />

(MBR) từ<br />

bắt đầu của cấu trúc.<br />

Chú ý: offsetofis vĩ mô không xác định cho bitfields. Một thông báo lỗi sẽ<br />

xảy ra nếu bitfields được sử dụng.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!