Giter Site home page Giter Site logo

rcseacord / cmp_int Goto Github PK

View Code? Open in Web Editor NEW
18.0 18.0 1.0 409 KB

C implementation of C++ Utility functions https://en.cppreference.com/w/cpp/utility/intcmp

License: MIT License

C 22.42% CMake 15.80% C++ 14.05% Makefile 45.93% TypeScript 1.09% Tcl 0.70%

cmp_int's People

Contributors

aaronballman avatar angvom avatar rcseacord avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

azurecloudmonk

cmp_int's Issues

Uses gcc extension

({ }) expressions are a gcc extension.

This is not necessary because all of that can be done in a single expression with nested ?: conditional.

integer types

Claiming that this works for "integer types" is kind of weird because it seems that by design it doesn't work for char and bool. I am not questionning that design, but then this should be made cristal clear in the documentation.

does not work for extended or bit-precise integer types

The case listing in the macros is quite restrictive. I think better would be something like

#define is_signed(X)    \
_Generic((X),               \
   bool: 0,                    \
   char: (char)-1 < 0,    \
   signed char: 1,         \
   signed short 1,         \
   unsigned char: 0,    \
   unsigned short: 0,   \
   default: (0 ? (X)%1 : -1) < 0 \
)

That ensures to work also for __int128 or other such wild animals if they exist, and to give the expected answer for char if the user has a concept of "could hold negative values" for being a signed type.

side effects of some expressions are doubled

int x = 0;
puts(cmp_less(x++, 0U) ? "true" : "false");
printf("%d\n", x);

Outputs:

false
2

Which can be fixed using statement expression, but statement expressions are non-standard.

expressions have type `int`

The C++ variant has bool return types. This should be the same, here. Just add a cast in front of the whole expression.

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.