Closed KyleCardoza closed 1 year ago
I looked at it and _Generic
is supported by Clang, but the AST translation I have in place does not handle it properly. I have fixed it for the next release. I played with the following code:
extern void stringFunc(char*);
extern void otherStringFunc(char*);
extern void string4Func(char[4]);
#define F(X) _Generic(&(X), \
default: otherStringFunc, \
char**: stringFunc, \
char(*)[4]: string4Func, \
char const**: stringFunc, \
char const(*)[4]: string4Func \
)(X)
void foo(char *p) {
F(p);
F("foo");
F("fooxx");
}
This now results in:
0015 void foo(char *p) {
\ 000000 .section farcode,text
\ 000000 .public foo
\ 000000 foo:
0016 F(p);
\ 000000 22...... jsl long:stringFunc
0017 F("foo");
\ 000004 a9.... lda ##_StringLiteral_foo
\ 000007 22...... jsl long:string4Func
0018 F("fooxx");
\ 00000b a9.... lda ##_StringLiteral_fooxx
\ 00000e 22...... jsl long:otherStringFunc
0019 }
\ 000012 6b rtl
Fantastic! You made my day! Thank you. Is there like a tip jar or something I can throw money at?
I was laid off from my current job three weeks ago, due to cost cuts and slowdown in the economy, so any contribution to the tip jar is welcome, but do not feel it is a requirement. If you want to, there is my Paypal hth313@gmail.com that can be used. I appreciate the comments you make, it widens my knowledge about C extensions and more recent things added to the language. It helps me improve the products and some of it I may end up using myself eventually.
What I do is, I set up a Ko-Fi (https://ko-fi.com) account and a Patreon, to allow people to support my work.
Far as comments go, I do have one other feature request at the moment, if you find you have time to look at it: __attribute__((overloadable))
, which is a Clang-specific attribute that applies C++-compatible name mangling function overloading to the plain C language. It's a bit easier to use than _Generic, but I have no idea if it's easier to make Calypsi use it.
We'll leave off asking about shoot-for-the-moon things like C++ or Objective-C support or the like for another day.
Feel free to open a new ticket with the overloadable
attribute, but I will probably need to wait a bit looking into it as I have work ahead with some library matters, board support and new targets.
C++ is of course supported by the Clang front end, there are a couple of issues for me supporting it.
I agree fully re: C++ -- I avoid using it at all costs, myself. Do you have similar feelings towards Objective-C, which is also supported by Clang but only adds things to standard C, rather than changing things that are already there? C++ is far more different from C than Objective-C is.
This is strictly hypothetical, of course, and you shouldn't be expected to provide the Obj-C runtime (I have a couple of good ones here, one of which has been thoroughly tested on low-end platforms like DOS PCs and the Nintendo DS!), but it's an interesting thought experiment at least.
I have honestly never used Objective-C so I do not really have much opinions about it, or even considered it. Rust is on my radar, if there at some point may be another language, though making further use of Clang may make more sense.
The thing is that I have so many other things that feels more important. A lot of that is also work that appeals to me. I would also like to find more time to use my own products.
Makes total sense to me. Just a thought experiment is all. Love the compiler, by the way.
Money for the tip jar reached the destination (me), thank you!
No worries. Sorry I don't have more to spare at the moment, but if you set up a Patreon I can promote it for you.
I know Calypsi targets C99, and I'm not trying to push for it being C11 or C23 instead -- I'm just wondering if it would be possible for there to be some way I could implement the type-generic
tgmath.h
macros for my project. _Generic (if it's less work for you, like, if the Clang frontend can do the grunt work?) would be ideal, since I can use it for other stuff too, but even just a compiler builtin or something would be enough.