Share your repls and programming experiences

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

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.

thenullified (150)

i dont understand c, so sorry

DynamicSquid (3558)

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

thenullified (150)

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

DynamicSquid (3558)

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

HahaYes (1212)

smh C++ in repl is kinda shy

Jakman (451)

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 (3558)

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

Jakman (451)

@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 (1357)

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

MocaCDeveloper (303)

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 (3558)

@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

MocaCDeveloper (303)

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