Beginning Linux Programming Third Edition phần 3

Có một số nhược điểm: Thực hiện một kịch bản thứ hai từ bên trong một kịch bản là chậm hơn so với thực hiện một chức năng. Đó là khó khăn hơn để vượt qua trở lại kết quả, và có thể có một số lượng rất lớn các kịch bản nhỏ. Bạn nên xem xét một phần nhỏ nhất của kịch bản của bạn một cách hợp lý đứng một mình và sử dụng | Chapter 4 You might also see C programs for Linux simply declaring main as main This will still work as the return type will default to int and formal parameters that are not used in a function need not be declared. argc and argv are still there but if you don t declare them you can t use them. Whenever the operating system starts a new program the parameters argc and argv are set up and passed to main. These parameters are usually supplied by another program very often the shell that has requested that the operating system start the new program. The shell takes the command line that it s given breaks it up into individual words and uses these for the argv array. Remember that a Linux shell normally performs wild card expansion of filename arguments before argc and argv are set whereas the MS-DOS shell expects programs to accept arguments with wild cards and perform their own wild card expansion. For example if we give the shell the following command myprog left right and center the program myprog will start at main with parameters argc 4 argv myprog left right and center Note that the argument count includes the name of the program itself and the argv array contains the program name as its first element argv 0 . Because we used quotes in the shell command the fourth argument consists of a string containing spaces. You ll be familiar with all of this if you ve programmed in ISO ANSI C. The arguments to main correspond to the positional parameters in shell scripts 0 1 and so on. While ISO ANSI C states that main must return int the X Open specification contains the explicit declaration given above. Command line arguments are useful for passing information to programs. For example we could use them in a database application to pass the name of the database we wish to use which would allow us to use the same program on more than one database. Many utility programs also use command line arguments to change their behavior or to set options. You would usually set these .

Không thể tạo bản xem trước, hãy bấm tải xuống
TÀI LIỆU MỚI ĐĂNG
260    1    1    14-06-2024
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.