Comments (7)
obs:
C23 also added _BitInt(N) and _Decimal32, _Decimal64, and _Decimal128.
C99 has complex.
Converting any of these types to C89 would require a review in expressions
and this work could be reused for operators overloading.
from cake.
One alternative is to convert expressions using operators to function call syntax.
For instance the expression
a + b * c
becomes
add(a , mult(b, c));
the names add,mult etc can be modified according with the types, for
instance, using struct tag.
Having that the programmer just provide the function implementation.
It also can be a function like macro. With _Generic the same name add etc can
be preserved.
from cake.
Yes, I did that in my code. And my code became a nightmare to understand. So, what I'm saying is a feature in Cake which would do the conversion for you, so that you don't need to make your code unreadable.
from cake.
C23 included the header <stdckdint.h>
bool ckd_add(type1 *result, type2 a, type3 b);
bool ckd_sub(type1 *result, type2 a, type3 b);
bool ckd_mul(type1 *result, type2 a, type3 b);
Maybe cake could automatic convert from expression syntax inside _safe_check( )
to a function adding the checks.
int main() {
int r = _safe_check(a + b *c);
if (errno != 0) printf("oops");
}
/*generated function*/
static int _expression_1(int a, int b, int c) {
int r;
if (ckd_mul(&r, b, c) != 0) errno = 1;
if (ckd_add(&r, a, r) != 0) errno = 1;
return r;
}
int main() {
int r = _expression_1(a, b, c);
if (errno != 0) printf("oops");
}
from cake.
I don't know that header yet. But I think that all the operators that can operate on integers and floating point types would be potentially necessary. Maybe even unary operators.
The purpose would be to let the client program implement its own integer and floating point types.
from cake.
Indeed, I feel that every C compiler should have offered this feature for years now, because it's really useful.
from cake.
Is there a place in the Cake source code where I could just modify the AST replacing every operator occurrence by a function invocation taking one or two arguments depending on whether the operator is unary or binary? (I left at a side the tertiary conditional operator because I don't think it makes sense to overload it: the only interest would be in inner expressions with other operators inside the tertiary operator, but not in the tertiary operator itself).
from cake.
Related Issues (20)
- missing error - f1(void) , f1(1)
- missing warning - unreferenced label
- missing warning using reserved macro
- missing warning - unrecognized character escape sequence
- missing warning - logical operation on address of string constant
- missing warning - const object should be initialized
- missing warning - bool like used in switch
- missing warning - case constant 'constant' too big for the type of the switch expression
- missing warning if (unsigned < 0)
- missing warning constant expression overflow (use safe int in constant expressions)
- missing warning negative used with unsigned int
- missing warning with enumerator to big for its size
- missing warning - empty controlled statement found; is this the intent?
- missing warning comparing null with int
- missing warning - operator 'operator-name': deprecated between enumerations of different types
- missing warning enum item not handled at switch
- fatal errors inside headers (level >0 ) are being ignored
- pragma failing on windows headers.. after pragma refactoring
- if with initializer not working HOT 1
- Feature: Tag compatibility HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cake.