Name mangling và language linkage là gì, và extern C bảo đảm hoặc không bảo đảm điều gì qua ranh giới ABI?
Xem đáp án và giải thích
C++ implementation thường encode namespace, overload signature và thông tin type khác vào linker name, nhưng mangling scheme là implementation ABI chứ không phải format portable của ngôn ngữ. extern "C" đặt C language linkage cho function name và function type, thường tạo exported name C có thể gọi và không cho overload C++ trên linkage name đó. Nó không làm class, exception, template, standard-library type, object layout hay memory ownership portable qua compiler và platform tùy ý. Boundary ổn định nên dùng dữ liệu tương thích C, ownership rule cố định, calling hoặc export attribute rõ ràng khi cần và giữ exception bên phía C++.
C++ implementation thường encode namespace, overload signature và thông tin type khác vào linker name, nhưng mangling scheme là implementation ABI chứ không phải format portable của ngôn ngữ. extern "C" đặt C language linkage cho function name và function type, thường tạo exported name C có thể gọi và không cho overload C++ trên linkage name đó. Nó không làm class, exception, template, standard-library type, object layout hay memory ownership portable qua compiler và platform tùy ý. Boundary ổn định nên dùng dữ liệu tương thích C, ownership rule cố định, calling hoặc export attribute rõ ràng khi cần và giữ exception bên phía C++.
Hãy liên hệ trực tiếp kết luận với kiểu, lifetime, ownership, overload resolution hoặc library contract xuất hiện trong câu hỏi. Nếu kết quả phụ thuộc implementation hoặc vi phạm precondition, cần nói rõ thay vì chỉ đoán output.