I am considering adding support for the most basic parameter forward
declarations, a feature not in standard C.
Consider a parameter that is an array at least as long as the value of
another parameter (via the C99 [static] syntax):
// OK, but some prefer the size to be the last argument.
void f(size_t i, char a[static i]);
// Not OK, size i is not known where it is used.
void f(char a[static i], size_t i);
// OK, but work for the definition only, and is not valid C23.
void f(a, i)
size_t i;
char a[static i];
{
}
// Parameter forward declaration.
void f(size_t i; char a[static i], size_t i);
IMO, parameter forward declarations are a reasonably simple feature to
bring back support for something that C lost with K&R functions. They
can help improve safety (making it possible to warn on passing an array
that is too short).
I'm considering to support the most basic parameter forward declarations
in SDCC: forward declaration of a single parameter of integer type.
Philipp
P.S.: Parameter forward declarations are quite controversial. Apple and
large parts of the clang community are strongly opposed to this feature,
so I don't think it will become part of a future C standard. Apple is
pushing for an alternative approach instead:
// "dependent attributes" approach
void f(char a[static __counted_by(i)], size_t i);
The approach by Apple also applies outside of parameter declarations,
but would substantially complicate parsing there. I don't see us
implementing it anytime soon, and I am unsure if the proposal will be
able to gather the necessary support to make it into the C standard.
GCC has supported parameter forward declarations since at least GCC
3.0.1, 24 years ago. The "most basic parameter forward declarations" I
want to support in SDCC are a subset of GCC parameter forward declarations.
_______________________________________________
Sdcc-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sdcc-user