Share your repls and programming experiences

← Back to all posts
Guys I think I broke C++
h
DynamicSquid (2673)

Take a look at the code (line 10). It works. Yes, there may be warnings, but that still means the code works! And to prove it works, I printed "Hello World" after the line of code which generates the warnings. That means that this is perfectly usable code.

Commentshotnewtop
thenullified (144)

i dont understand c, so sorry

DynamicSquid (2673)

@thenullified line 10, you can clearly see the problem there

thenullified (144)

i assume that is a invalid syntax? like ilikesquid in python without the '' ? @DynamicSquid

DynamicSquid (2673)

@thenullified no, its not invalid! that's the cool part!

HahaYes (1052)

smh C++ in repl is kinda shy

Jakman (377)

nice but it is pretty easy to make some define constants and use them as syntax. this is just what C allows you to do as an alternate for making types.

DynamicSquid (2673)

@Jakman yeah. wait, is C/C++ the only language that allows you to do this?

Jakman (377)

@DynamicSquid objective C allows you to do this too. The B programming language does too but people wont get to see that because of how old and forgotten B is

Highwayman (1367)

lol. Hm... how har can we extend this...
Wait actually....

#define hello /* no op. */
#define there /* no op. */
#define my /* no op. */
#define name /* no op. */
#define is /* no op. */
#define highwayman /* no op. */

hello there my name is highwayman
int main() {}

Edit: or even just define them to be nothing at all...
#define word

targetfanttthat (98)

You didn't break it.
The compiler sees that the variables I, am, a and squid are defined, and having a ',' is used in multi-declarations. Example declaring 2 values on one line.
So..the clang compiler logically does as following:
"oh, I is defined, I see I but no action on I, this is a warning".

DynamicSquid (2673)

@targetfanttthat Well, I didn't mean that, but I am, a squid; isn't a line of code you would normally see in any language

targetfanttthat (98)

@DynamicSquid Ohh gotcha. I thought you were legitimately meaning you broke it.. lol