https://bugs.llvm.org/show_bug.cgi?id=37148
Bug ID: 37148
Summary: Feature Request: More _Generic Generics
Product: clang
Version: unspecified
Hardware: PC
OS: Windows NT
Status: NEW
Severity: enhancement
Priority: P
Component: Frontend
Assignee: unassignedclangb...@nondot.org
Reporter: bumblebritche...@gmail.com
CC: llvm-bugs@lists.llvm.org
I'm not sure how or where to file this feature request, I was talking to Jens
Gustedt, who sits on the C standardization board, about a feature idea I had,
and he said that I basically have to find an implementation to create my
feature first before it can become the standard, which makes enough sense.
So if this is the wrong place to put this, I'd love to hear where the right
place would be.
Anyway, here's my idea for C:
What are the advantages over C++'s templates?
This method would allow a function to be created with a reasonable amount of
"genericity", without allowing everything including the kitchen sink like has
to be accepted now, and like C11's _Generic, it would not bloat the compile
time, they'd be already existing functions and the linker would just choose
which one to use at link time.
`_Typeof((((uint8_t,uint16_t), ArrayType), uint8_t:InitArray8,
uint16_t:InitArray16) uint64_t NumPlanes, uint64_t PlaneSize)(NumPlanes,
PlaneSize);`
`_Typeof((((uint8_t*,uint16_t*), Format), uint8_t*:FormatString8,
uint16_t*:FormatString16), _Typeof((*), ...))(Format, __VA_ARGS__);`
`FormatString8((_Typeof((uint8_t*,uint16_t*), Format), ...) {`
` Types CurrentType = _Typeof(...[1]);`
` if (CurrentType == uint8_t || CurrentType == uint16_t || CurrentType ==
uint32_t || CurrentType == uint64_t) { ConvertInteger2String(...[1]); }`
`}`
So the format would be:
Return type: Supports a comma separated list of integral types.
Function parameters: Supports a comma separated list of integral types, or an
asterisk for any integral type
For the variadic variation, I think simply allowing the user of the
_Typeof(...[X]) could do the trick.
As for the complexity of parsing, and the backend and whatnot, I don't have a
clue, I'm not a compiler writer, I'm just some dude with an idea for how to
make C better.
--
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs