TAILIEUCHUNG - Thinking in C plus plus (P11)

Tham khảo tài liệu 'thinking in c plus plus (p11)', công nghệ thông tin, kỹ thuật lập trình phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | defined types by value during function calls. It s so important in fact that the compiler will automatically synthesize a copyconstructor if you don t provide one yourself as you will see. Passing returning by value To understand the need for the copy-constructor consider the way C handles passing and returning variables by value during function calls. If you declare a function and make a function call int f int x char c int g f a b how does the compiler know how to pass and return those variables It just knows The range of the types it must deal with is so small - char int float double and their variations - that this information is built into the compiler. If you figure out how to generate assembly code with your compiler and determine the statements generated by the function call to f you ll get the equivalent of push b push a call f add sp 4 mov g register a This code has been cleaned up significantly to make it generic the expressions for b and a will be different depending on whether the variables are global in which case they will be _b and _a or local the compiler will index them off the stack pointer . This is also true for the expression for g. The appearance of the call to f will depend on your name-decoration scheme and register a depends on how the CPU registers are named within your assembler. The logic behind the code however will remain the same. In C and C arguments are first pushed on the stack from right to left then the function call is made. The calling code is responsible 480 Thinking in C www. BruceEckel .com for cleaning the arguments off the stack which accounts for the add sp 4 . But notice that to pass the arguments by value the compiler simply pushes copies on the stack - it knows how big they are and that pushing those arguments makes accurate copies of them. The return value of f is placed in a register. Again the compiler knows everything there is to know about the return value type because that type is built into the language so the

TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã 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.