Voting

Category

real language

Bookmarking

Del.icio.us Digg Diigo DZone Earthlink Google Kick.ie
Windows Live LookLater Ma.gnolia Reddit Rojo StumbleUpon Technorati

Language C/C++ Preprocessor

Date:04/20/05
Author:Wim Rijnders
URL:n/a
Comments:7
Info:n/a
Score: (3.03 in 255 votes)
This is the pre-processor for C or C++.  Normally, not a language 
in itself, but created to make using C/C++ easier.  This is a 
novel use of the pre-processor

-- BEER.CPP ---------------------------------------------------------
// 99 Bottles written entirely in Visual C++ preprocessor directives.
// By Wim Rijnders.
#pragma warning(disable : 4005 )

#define BOTTLES "bottles"
#define TAKE_ONE_DOWN "Take one down, pass it around,"
#define DEC_NUM 9
#define DEC_STR "9"
#define DEC2_NUM 9
#define DEC2_STR "9"

#define TEST_BOTTLES(a,b) (DEC2_NUM == a  && DEC_NUM == b )
#define STILL_HAVE__BOTTLES !TEST_BOTTLES(0,0)
#define NO_MORE__BOTTLES TEST_BOTTLES(0,0)
#define JUST_ONE__BOTTLE TEST_BOTTLES(0,1)

#define OF_BEER DEC2_STR DEC_STR " " BOTTLES " of beer"
#define BEER_ON_WALL OF_BEER " on the wall"

#include "sing.h"
-- SING.H -----------------------------------------------------------
//Following to beat the 32-file include limit of VC
#if STILL_HAVE__BOTTLES
	#include "stanza.h"               
	#include "stanza.h"               
	#include "stanza.h"               
	#include "stanza.h"               
	#include "sing.h"               
#endif 
-- STANZA.H ---------------------------------------------------------
#if STILL_HAVE__BOTTLES
	#pragma message(BEER_ON_WALL ",")
	#pragma message(OF_BEER ",")
	#pragma message(TAKE_ONE_DOWN)
	
	#include "dec.h"         
	#if NO_MORE__BOTTLES
		#define DEC2_STR ""
		#define DEC_STR "No more"
	#endif	
	
	#if JUST_ONE__BOTTLE
		#define BOTTLES "bottle"
	#else
		#define BOTTLES "bottles"	
	#endif
	
	#pragma message(BEER_ON_WALL ".")
	#pragma message("")
#endif 
-- DEC.H ------------------------------------------------------------
#if DEC_NUM == 9
	#define DEC_NUM 8
	#define DEC_STR "8"
#elif DEC_NUM == 8
	#define DEC_NUM 7
	#define DEC_STR "7"
#elif DEC_NUM == 7
	#define DEC_NUM 6
	#define DEC_STR "6"
#elif DEC_NUM == 6
	#define DEC_NUM 5
	#define DEC_STR "5"
#elif DEC_NUM == 5
	#define DEC_NUM 4
	#define DEC_STR "4"
#elif DEC_NUM == 4
	#define DEC_NUM 3
	#define DEC_STR "3"
#elif DEC_NUM == 3
	#define DEC_NUM 2
	#define DEC_STR "2"
#elif DEC_NUM == 2
	#define DEC_NUM 1
	#define DEC_STR "1"
#elif DEC_NUM == 1
	#define DEC_NUM 0
	#define DEC_STR "0"
#elif DEC_NUM == 0    
	#include "dec2.h"
	#define DEC_NUM 9
	#define DEC_STR "9"
#endif   
-- DEC2.H -----------------------------------------------------------
#if DEC2_NUM == 9
	#define DEC2_NUM 8
	#define DEC2_STR "8"
#elif DEC2_NUM == 8
	#define DEC2_NUM 7
	#define DEC2_STR "7"
#elif DEC2_NUM == 7
	#define DEC2_NUM 6
	#define DEC2_STR "6"
#elif DEC2_NUM == 6
	#define DEC2_NUM 5
	#define DEC2_STR "5"
#elif DEC2_NUM == 5
	#define DEC2_NUM 4
	#define DEC2_STR "4"
#elif DEC2_NUM == 4
	#define DEC2_NUM 3
	#define DEC2_STR "3"
#elif DEC2_NUM == 3
	#define DEC2_NUM 2
	#define DEC2_STR "2"
#elif DEC2_NUM == 2
	#define DEC2_NUM 1
	#define DEC2_STR "1"
#elif DEC2_NUM == 1
	#define DEC2_NUM 0
	#define DEC2_STR ""
#endif

Download Source | Write Comment

Alternative Versions

VersionAuthorDateCommentsRate
Direct output (general / GNU)Gerry JJ12/30/052
with Order interpreterVesa Karvonen12/30/051

Comments

>>  mwGamera said on 11/23/05 16:10:31

mwGamera Wow, great idea to use preprocessor :D
I like it.

>>  Jay said on 12/04/05 12:38:10

Jay LOL that is the dirtiest use of C/C++ I have ever seen. Awesome :)

>>  vurk said on 07/28/06 16:29:17

vurk haha that rocks!

>>  C Master said on 10/29/06 22:15:06

C Master How bloody lord!!! =O

>>  Best Registry Cleaner Tools said on 01/10/10 13:13:54

Best Registry Cleaner Tools Thanks for this! I really like this and hope you get the most out of it

>>  orm said on 02/17/10 20:45:10

orm My facepalm facepalmed when I read this. Very clever.

>>  Video capturelo said on 07/15/10 10:24:10

Video capturelo Total Screen Recorder could record the video as long as you wish. Not like the other screen recorder, which just let you record one minute or with large watermark on the video.
http://www.totalscreenrecorder.com

GodswMobile Software dedicated to providing a better experience life for the people who use and rely upon Microsoft Windows Mobile devices for their personal and commercial needs. With thousands of users over 50 countries worldwide, GodswMobile has become the popular, trusted and convenient choice to backup and restore the valuable information which stored in mobile phones.
http://www.godswmobile.com/

Download Source | Write Comment

Add Comment

Please provide a value for the fields Name, Comment and Security Code.
This is a gravatar-friendly website.
E-mail addresses will never be shown.
Enter your e-mail address to use your gravatar.

Please don't post large portions of code here! Use the form to submit new examples or updates instead!

Name:

eMail:

URL:

Security Code:
  
Comment: