💯 Cursed code

Same code compiles in both C and C++ and can detect which version of C and C++ with language features alone.

With not be taking questions.

#cplusplus
#programming #if true #define ISC 0 #els...
I have added this to my github "determine_c_or_cpp" repo: github.com/shafik/determi…

Enjoy!
I feel compelled by some of the comments in quote tweets of this, to point out this should not be used in production.

We have standard macros for detecting C and C++ versions. Please use those: godbolt.org/z/c7P1EEq95

OTOH for IOCCC entries use this. #include <stdio.h>  int mai...

• • •

Missing some Tweet in this thread? You can try to force a refresh
 

Keep Current with The Grinch Who Gave Back Cursed Code

The Grinch Who Gave Back Cursed Code Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @shafikyaghmour

18 Sep 20
Structure and Interpretation of Computer Programs: SICP
By @code_report

Why SICP matters?

#CppCon
#Cplusplus Image
@code_report Pascal is for building pyramids

Lisp is for building organisms Image
@code_report "We write awful code" Image
Read 4 tweets
31 May 19
Let’s do this:

One Like, One Undefined Behavior.

I plan on running this through the weekend at least.

#Cplusplus
#Programming
Signed integer overflow/underflow is undefined behavior

int x1=std::numeric_limits<int>::max()+1;
int x2=std::numeric_limits<int>::min()-1;

[expr.pre]p4 eel.is/c++draft/expr#…

godbolt: godbolt.org/z/Ga-fbb
#2 Signed integer overflow/underflow is undefined behavior 2

int x3=std::numeric_limits<int>::min() / -1;

[expr.pre]p4 eel.is/c++draft/expr#…

godbolt: godbolt.org/z/ytC8oi
Read 65 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal Become our Patreon

Thank you for your support!

Follow Us on Twitter!

:(