rain-1 / linenoise-mob

A small self-contained alternative to readline and libedit
BSD 2-Clause "Simplified" License
66 stars 10 forks source link

Do not use 'new' as a variable name and make casts explicit #47

Closed ronchaine closed 5 years ago

ronchaine commented 5 years ago

Done to allow compiling in C++ mode. C++ requires explicit casts from void pointers and uses 'new' as a keyword

rain-1 commented 5 years ago

I would accept to not use 'new' as a variable name, but not casting malloc.

What is the reason for compiling C code as C++? Can't you just compile it as C then link it to your C++ program?

ronchaine commented 5 years ago

Yes, it's of course possible to compile as C and link it to C++ programs. There are few reasons not to do so, though. Don't know if any of them are important enough to change your mind though.

C++ compilers do stricter type-checking, which is preferable in some cases, especially in the embedded world.

It is more cumbersome to do the linking. One of the best features of linenoise compared to alternatives is that I can just quickly drop it into a project and do a fast one-line-compile.

I could put the casts behind a #ifdef __cplusplus and some macro that calls a malloc either with or without the cast, if that would be acceptable, but not sure if that makes the code too messy (it probably does).

Anyways, feel free to close this if its unwanted.