Sign in to follow this  
3DModelerMan

Preprocessor on same line as code

Recommended Posts

3DModelerMan    1173
As an exercise I recently challenged myself to try and write a program in only one line of code. I've come pretty far into it, but one thing bugs me, and doesn't really make it a one liner. When I include iostream it has to have a linebreak. Is there anything in the C++ standard that allows you to put preprocessor statements on the same line as regular code?

Share this post


Link to post
Share on other sites
fastcall22    10838
Include the contents of the header and expand all the macros into one line? ([url=http://msdn.microsoft.com/en-us/library/8z9z0bx6%28v=vs.110%29.aspx]Preprocess to file[/url], [url=http://msdn.microsoft.com/en-us/library/hdkef6tk(v=vs.110).aspx]ShowIncludes[/url]) Edited by fastcall22

Share this post


Link to post
Share on other sites
tanzanite7    1410
[quote name='fastcall22' timestamp='1342925622' post='4961837']
Include the contents of the header and expand all the macros into one line?
[/quote]You mean, create a gigantic one-line file ... several megabytes ... somehow i doubt OP will find it acceptable :/

/me has been hit with a similar problem in the past (macro-based boiler-plate code-gen issues) and i did not find any workarounds, i doubt there is any (besides adding a custom compilation step before preprocessor). Edited by tanzanite7

Share this post


Link to post
Share on other sites
Daaark    3553
Why not challenge yourself to do something [u]useful[/u]?

1) Including several hundred lines of iostream code into your own isn't a 1 line program. If you are going to do that, you might as well just include an entire program and have your 1 line be [i]Go()[/i];

2) 'Lines' is a useless metric. C++ is freeform and lines are just whitespace to be stripped out anyways. Cramming 15 statements into one line doesn't make it a 1 line program. It's just a poorly formatted 15 line program. Edited by Daaark

Share this post


Link to post
Share on other sites
Neometron    606
I'm kind of interested in seeing your one liner.

I agree with Daaark that lines are a useless metric. I suppose a better one is exe file size. There are impressive 3d tech demos out on the internet including music and it all fits within 64KB limit.

Share this post


Link to post
Share on other sites
tanzanite7    1410
edit: damn, ninja post, this is in response to Daaark's post.

Don't know what OP had in mind, but i think you are missing the point.

It is NOT intended to be useful nor well readable etc. It is a challenge, bonus points if the code does something interesting. Check for example [url="http://mrl.nyu.edu/~perlin/"]this (at the top of Ken Perlin's homepage)[/url]. Edited by tanzanite7

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this