Tag Archives: programming

C++ humor: a –do not modify the comments or format– horror code

just in case you think, you can understand what the code is doing by looking at it

executable at Ideone

#include <iostream>
#define B(l,a) __##l##E##__
#define _O_ ((1<<2>>1<<1)-2)
#define _h_ 7-3
#define _C_ (7/_h_)
#define _r_ ((1<<0)+0x00a/2+_C_)
#define _a_ ((1<<5)-_r_)
#define _p_ { void _(){} namespace
#define printf(_0_) squeak(_O_,B(LIN,!)-_a_); _
 
// this
// is weird
 
namespace _p_ {
void squeak(int,int who) {      switch (who) {
                case _O_: std::cout<<"\x71\x75\x61\x6b"<<std::endl; break;
                case (_h_+_C_-2): std::cout<<"\x6d\x65\x6f\x77"<<std::endl; break;
                case _h_: std::cout<<"\x62\x6f\x77"<<std::endl; break;
                default: std::cout<<"\x62\x6c\x61\x68"<<std::endl; break;
        };
}}
}
 
// do not review ...
 
int main()
{
        printf("hello\n");
        printf("this\n");
        printf("is\n");
        printf("not\n");
        printf("funny\n");
        printf("at all!\n");
        return 0;
}
 
//expected output:
//meow
//blah
//quak
//blah
//bow
//blah

 

On unwanted access to inner classes in C++11

#include <iostream>
#include <typeinfo>

class Outer {
private:
	class Inner {
	public:
		void Do() {
			std::cout<<"Do"<<std::endl;
		}
	};
private:
	Inner inner;
public:
	Inner& Get() {
		return inner;
	}
};

int main()
{
	Outer O;
	// err: private Outer::Inner
    // Outer::Inner& x=O.Get(); x.Do();
    auto& x=O.Get();
    x.Do(); // ok
    std::cout << typeid(x).name() << std::endl;  
    O.Get().Do(); // ok
    return 0;
}