GithubHelp home page GithubHelp logo

Comments (7)

thradams avatar thradams commented on June 2, 2024 1

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.

thradams avatar thradams commented on June 2, 2024

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.

cblc avatar cblc commented on June 2, 2024

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.

thradams avatar thradams commented on June 2, 2024

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.

cblc avatar cblc commented on June 2, 2024

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.

cblc avatar cblc commented on June 2, 2024

Indeed, I feel that every C compiler should have offered this feature for years now, because it's really useful.

from cake.

cblc avatar cblc commented on June 2, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.