To make my code more concise, can I do something like
int f(int const x, y, z), g(int const x, y, z);
to declare functions f and g which each take three int const arguments?
Edit: Perhaps here is a better example:
int f(int const a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z);
How would that not be more concise and readable than putting int const before every letter?
For C code, if you really insist on it, you can use old-style (K&R) function headers:
typedef int const cint;
int f(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z)
cint a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z;
{
// function body here
}
Note that I'm not recommending this -- and C++ doesn't support this anyway, so the only way you could use it would be to compile the function itself in C, and include an extern "C" declaration to access it from C++.
I'd also note, however, that the whole idea strikes me as silly anyway. First, a function that has enough parameters for this to be worth considering is basically guaranteed to be a disaster. Second, top-level const (i.e., applying to the parameter itself, not what it points at or refers to) is completely meaningless, and (IMO) a lousy idea in any case.
Using Boost preprocessor, and considering you don't care to describe the function arguments one by one (but isn't that the point of your question), you can use the following trick :
#include <boost/preprocessor/repetition/enum_params.hpp>
int f( BOOST_PP_ENUM_PARAMS(26, int const arg) );
But don't forget that the whole idea of not taking the required time and space to describe function arguments is very dangerous.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With