Discussion Overview
The discussion revolves around the possibility of defining a function in C or C++ that can determine the number of arguments passed to it without using a terminating null or explicitly specifying the count. The conversation touches on variadic functions, templates, and the handling of variable argument lists in both languages.
Discussion Character
- Technical explanation
- Debate/contested
Main Points Raised
- Some participants assert that in C, it is not possible to know the number of arguments in a variadic function without a terminating null or explicit count.
- Others mention that C99 and C++11 introduced variadic macros and templates, which allow for more flexible handling of arguments, but do not resolve the original question for C.
- One participant provides a C++ example using variadic templates to demonstrate how to count and print arguments, highlighting the use of `sizeof...(args)`.
- There is a contention regarding the standard way C handles variable arguments, with some stating that it lacks a mechanism to determine the number or types of unnamed arguments, while others argue that it provides facilities for stepping through such lists.
- Concerns are raised about the use of C++11 features, particularly regarding object slicing and the handling of complex user-defined types in loops.
- Participants discuss the implications of inheritance and object slicing in C++, suggesting that careful design can mitigate some issues.
Areas of Agreement / Disagreement
Participants do not reach a consensus on the capabilities of C regarding variadic functions, with some asserting limitations while others highlight available mechanisms. The discussion remains unresolved regarding the best practices for handling variable arguments in C and C++.
Contextual Notes
Limitations include the lack of a standard mechanism in C for determining the number of unnamed arguments, and the potential issues with object slicing in C++ when using certain features.