Jump to content

View more

Image of the Day

The night is still, but the invasion brings chaos. #screenshotsaturday #hanako #indiegame #gameart #ue4 #samurai https://t.co/cgILXuokoS
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

Preprocessor on same line as code

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
7 replies to this topic

#1 3DModelerMan   Members   

1173
Like
0Likes
Like

Posted 21 July 2012 - 07:56 PM

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?

#2 zacaj   Members   

663
Like
0Likes
Like

Posted 21 July 2012 - 08:11 PM

Forward declare everything you use and put the include at the end?

#3 fastcall22   Moderators   

10694
Like
0Likes
Like

Posted 21 July 2012 - 08:53 PM

Include the contents of the header and expand all the macros into one line? (Preprocess to file, ShowIncludes)

Edited by fastcall22, 21 July 2012 - 09:03 PM.

zlib: eJzVVLsSAiEQ6/1qCwoK i7PxA/2S2zMOZljYB1TO ZG7OhUtiduH9egZQCJH9 KcJyo4Wq9t0/RXkKmjx+ cgU4FIMWHhKCU+o/Nx2R LEPgQWLtnfcErbiEl0u4 0UrMghhZewgYcptoEF42 YMj+Z1kg+bVvqxhyo17h nUf+h4b2W4bR4XO01TJ7 qFNzA7jjbxyL71Avh6Tv odnFk4hnxxAf4w6496Kd OgH7/RxC

#4 tanzanite7   Members   

1410
Like
0Likes
Like

Posted 22 July 2012 - 10:39 AM

Include the contents of the header and expand all the macros into one line?

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, 22 July 2012 - 10:40 AM.


#5 MrDaaark   Members   

3552
Like
2Likes
Like

Posted 22 July 2012 - 11:12 AM

Why not challenge yourself to do something useful?

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 Go();

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, 22 July 2012 - 11:13 AM.


#6 Neometron   Members   

555
Like
2Likes
Like

Posted 22 July 2012 - 11:33 AM

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.

#7 tanzanite7   Members   

1410
Like
-1Likes
Like

Posted 22 July 2012 - 11:38 AM

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 this (at the top of Ken Perlin's homepage).

Edited by tanzanite7, 22 July 2012 - 11:39 AM.


#8 nobodynews   Members   

3095
Like
0Likes
Like

Posted 22 July 2012 - 02:52 PM

At least for GCC you can include a file on the command line: link.

C++: A Dialog | C++0x Features: Part1 (lambdas, auto, static_assert) , Part 2 (rvalue references) , Part 3 (decltype) | Write Games | Fix Your Timestep!





Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.