Lập trình C nâng cao - Fit Lec 3 (HUST) GV.AnhTT
- 페이지 수
- 11
- 형식
- 크기
- 122 KB
- Trường
- Đại học Bách khoa Hà Nội
- 조회수
- 0
- 댓글
- 0
- Lượt tải
- 0
미리보기 생성 중...
Slide bài giảng về lập trình generic trong C, giới thiệu khái niệm generic programming và cách xây dựng các hàm generic như memcpy, search, sort sử dụng con trỏ hàm để xử lý dữ liệu tổng quát.
- 문서명
- Lập trình C nâng cao - Fit Lec 3 (HUST) GV.AnhTT
- 학교 / 강의
- Đại học Bách khoa Hà Nội · Lập trình C
- 작성자 (문서 내)
- AnhTT
- 내용
- Tài liệu này hướng dẫn về lập trình generic trong C, minh họa bằng hàm memcpy và cách xây dựng các hàm generic khác như tìm kiếm và sắp xếp, sử dụng con trỏ void* và con trỏ hàm để đạt được tính tổng quát.
- 목차
- Generic programming
- Introduction
- memcpy
- Generic functions
- Implementation (1)
- Implementation (2)
- How to use ?
- Quiz 1
- Instruction
- Solution
- 페이지 수
- 11 페이지
- 업로더
- lienhejb
설명
Trích nội dung tài liệu
Generic programming anhtt-fit@mail.hut.edu.vn dungct@it-hut.edu.vn Introduction Generic programming is about generalizing software components so that they can be easily reused in a wide variety of situations. As a simple example of generic programming, the memcpy() function of the C standard library is a generic function to copy data from a container to another. void* memcpy(void* region1, const void* region2, size_t n); The memcpy() function is already generalized to some extent by the use of void* so that the function can be used to copy arrays of different kinds of data. Generally, to copy data we need to know only the address and the size of the container to copy. 1 memcpy An implementation of memcpy() might look like the following: void* memcpy(void* region1, const void* region2, size_t n) { const char* first = (const char*) region2; const char* last = ((const char*) region2) + n; char* result = (char*) region1; while (first != last) *result++ = *first++; return result; } Generic functions In a generic function, data should be passed in a generic way (by address and size). If the algorithm demands a specific function to manipulate data (e.g.., compare two values), such a function should be passed using a function pointer. Example: A generic search function on an array. How to pass data to this function ? How the algorithm can detect if two data items in the array is equal or not ? 2 Implementation (1) A generic data array should be passed as the following parameters void * buf: the address of the buffer containing the array’s data int size: the size of a data item in the array int total: the total number of data items in the array The search algorithm need also a function to compare the data items in the array for searching. A data item passe
자주 묻는 질문
이 문서는 무료인가요?
네. “Lập trình C nâng cao - Fit Lec 3 (HUST) GV.AnhTT” 문서는 무료입니다. 로그인 후 '다운로드'를 클릭하여 원본 파일을 받으세요.
이 문서는 몇 페이지로 되어 있나요?
이 문서는 11페이지입니다, Lập trình C 과정용. 다운로드하기 전에 온라인으로 미리 볼 수 있습니다.
다운로드하기 전에 미리 볼 수 있나요?
네. 이 페이지의 온라인 리더를 통해 문서를 미리 본 후 다운로드 여부를 결정할 수 있습니다.
Lập trình C nâng cao - Fit Lec 3 (HUST) GV.AnhTT
미리보기 생성 중...
Trích nội dung tài liệu
Generic programming anhtt-fit@mail.hut.edu.vn dungct@it-hut.edu.vn Introduction Generic programming is about generalizing software components so that they can be easily reused in a wide variety of situations. As a simple example of generic programming, the memcpy() function of the C standard library is a generic function to copy data from a container to another. void* memcpy(void* region1, const void* region2, size_t n); The memcpy() function is already generalized to some extent by the use of void* so that the function can be used to copy arrays of different kinds of data. Generally, to copy data we need to know only the address and the size of the container to copy. 1 memcpy An implementation of memcpy() might look like the following: void* memcpy(void* region1, const void* region2, size_t n) { const char* first = (const char*) region2; const char* last = ((const char*) region2) + n; char* result = (char*) region1; while (first != last) *result++ = *first++; return result; } Generic functions In a generic function, data should be passed in a generic way (by address and size). If the algorithm demands a specific function to manipulate data (e.g.., compare two values), such a function should be passed using a function pointer. Example: A generic search function on an array. How to pass data to this function ? How the algorithm can detect if two data items in the array is equal or not ? 2 Implementation (1) A generic data array should be passed as the following parameters void * buf: the address of the buffer containing the array’s data int size: the size of a data item in the array int total: the total number of data items in the array The search algorithm need also a function to compare the data items in the array for searching. A data item passe
- 문서명
- Lập trình C nâng cao - Fit Lec 3 (HUST) GV.AnhTT
- 학교 / 강의
- Đại học Bách khoa Hà Nội · Lập trình C
- 작성자 (문서 내)
- AnhTT
- 내용
- Tài liệu này hướng dẫn về lập trình generic trong C, minh họa bằng hàm memcpy và cách xây dựng các hàm generic khác như tìm kiếm và sắp xếp, sử dụng con trỏ void* và con trỏ hàm để đạt được tính tổng quát.
- 목차
- Generic programming
- Introduction
- memcpy
- Generic functions
- Implementation (1)
- Implementation (2)
- How to use ?
- Quiz 1
- Instruction
- Solution
- 페이지 수
- 11 페이지
- 업로더
- lienhejb
댓글 (0)
댓글이 없습니다. 첫 댓글을 남겨보세요!
K5 Bộ đề luyện thi Trạng Nguyên Tiếng Việt (NXB DHQG)
K2 Bộ đề luyện thi Trạng Nguyên Tiếng Việt (NXB DHQG)
K3 Bộ đề luyện thi Trạng Nguyên Tiếng Việt (NXB DHQG)
K4 Bộ đề luyện thi Trạng Nguyên Tiếng Việt (NXB DHQG)
K1 Bộ đề luyện thi Trạng Nguyên Tiếng Việt (NXB DHQG)

댓글 (0)
댓글이 없습니다. 첫 댓글을 남겨보세요!