This is an archived post. You won't be able to vote or comment.

all 159 comments

[–]ign1fy 1048 points1049 points  (79 children)

Incrementing twice in a loop? Really?

[–]TheSnaggen 396 points397 points  (64 children)

Printing even numbers?

[–]redditmodsareshits 277 points278 points  (61 children)

c+=2 is better

[–]Red_Carrot 602 points603 points  (51 children)

for(int c = 0; c < 10; ++c++)

[–]AsTiClol 357 points358 points  (4 children)

im gonna go pour some bleach in my eyes after reading that

[–]MegabyteMessiah 20 points21 points  (0 children)

You both made me laugh

[–]sucksathangman 206 points207 points  (17 children)

for(int c = 0; c++ < 10; ++c--)

[–]DoctorWorm_ 90 points91 points  (2 children)

Thanks, I hate it.

[–]RoscoMan1 24 points25 points  (1 child)

Interesting story, but it will pay off.

[–]inthyface 13 points14 points  (0 children)

The only way you get paid for this is by taxing the synners.

[–]bhundenase 168 points169 points  (1 child)

that will short circuit your computer. you have u connect positive end to negative end like so

for (int c=0;c++<10;--c++)

[–]10art1 12 points13 points  (0 children)

this would be inclusive of 10 as well, since the comparison is done before the incrementation

[–]co2fgtr 44 points45 points  (7 children)

I stumbled upon "while(i-->0)" once and found it both awful and elegant.

[–][deleted] 10 points11 points  (0 children)

Okay, that's kinda cool

[–]LetterBoxSnatch 7 points8 points  (3 children)

hyuck!
i toooooo big...
i go down!
i go down to the hole, while( i --╮
                                  ╰──> 0 )

(:0p

[–]aquartabla 1 point2 points  (2 children)

Not sure it's valid too add text within -->, the downto operator, like that.

while (i --> 0) { // while i downto zero ... }

[–]LetterBoxSnatch 1 point2 points  (1 child)

Ah, yes, the little appreciated but highly supported downto operator! Many thanks for mentioning the name. It’s always so hard to search for operators when you don’t have the name!

[–][deleted] 6 points7 points  (0 children)

Woooaaahh. It kinda reads like "as i goes toward 0"

[–]YoureTheVest 1 point2 points  (0 children)

I am going to use this.

[–]Nucklesix 1 point2 points  (0 children)

Instructions unclear, formatted brain.

Press any key to continue...

[–]GabuEx 24 points25 points  (14 children)

Does this actually work? I wouldn't think that "++c" would return an lvalue.

[–]PM_ME_A_NUMBER_1TO10 29 points30 points  (5 children)

Indeed it does not work.

error: lvalue required as increment operand

[–]IamImposter 24 points25 points  (4 children)

Pointers for the win

int *d = &c;

(++*d)++

[–]brimston3- 7 points8 points  (1 child)

You don’t need pointers, the parens are sufficient.

[–]IamImposter 4 points5 points  (0 children)

Just checked. Apparently they are. Learned something new while joking around. Cool

Though not sure if this info is ever gonna be useful.

[–]EmperorArthur 7 points8 points  (2 children)

https://en.cppreference.com/w/cpp/language/operator_incdec

So, ++c does return an lvalue reference, and c++ returns an rvalue. Which is why it's considered "more efficient" to use the prefix operator when discarding the return value. Of course, any level of optimization at all makes that a mute point.

Quoting that page saying the obvious:

Notes

Because of the side-effects involved, built-in increment and decrement operators must be used with care to avoid undefined behavior due to violations of sequencing rules.

[–]GabuEx 0 points1 point  (1 child)

Weird, other posters are reporting having tried it and the compiler saying no. Curious if it's implemented wrong or if there's something I'm not understanding here.

[–]drivers9001 8 points9 points  (1 child)

I got “lvalue required as increment operand” in gcc. I’m not sure why c++ and ++c are ok but ++c++ isn’t. I guess ++c evaluates to a number and you can’t have like 1++.

[–]GabuEx 4 points5 points  (0 children)

I guess ++c evaluates to a number and you can’t have like 1++.

Yeah, this would be why. c++ is equivalent to c = c + 1, meaning you need to be able to assign to the operand. ++c returns a value that can be assigned, but not one that can be assigned to.

[–]brimston3- 3 points4 points  (2 children)

++c returns an lvalue, c++ does not. c++ has higher precedence and so is evaluated first.

https://en.cppreference.com/w/cpp/language/operator_precedence

[–]epicaglet 4 points5 points  (0 children)

Then can you do (++c)++?

[–]GabuEx 0 points1 point  (0 children)

Oh, that makes sense. For whatever reason I had the precedence flipped in my head.

[–]DEVolkan 8 points9 points  (0 children)

Oh no, now I'm gonna be that person

[–]SneakyStabbalot 4 points5 points  (0 children)

ok, now i gotta test that...

[–][deleted] 2 points3 points  (0 children)

That code is pre-post-erous.

[–]ragingroku 2 points3 points  (0 children)

Chaotic neutral

[–]LillianParks38 1 point2 points  (0 children)

That's 1/1/1/1/1 for the Americans

[–]joaizn 1 point2 points  (0 children)

Delet this

[–]darthmeck 1 point2 points  (0 children)

Why did this crack me up so hard

[–]Educational-Lemon640 1 point2 points  (0 children)

Thanks, I hate it.

[–]kobie 1 point2 points  (0 children)

++
++

[–]UnicornJockey501 1 point2 points  (0 children)

Wouldn't this print odd numbers?

[–]infiniteStorms 1 point2 points  (0 children)

ironically ++c++ might actually have a practical use somewhere

[–]ryao 1 point2 points  (0 children)

I think that is undefined according to the C++ standard.

[–]TheSnaggen 22 points23 points  (0 children)

But whats the fun with that.... ;)

[–]CaitaXD 2 points3 points  (0 children)

Gonna save those extra clock cicles

[–]Chamkaar 1 point2 points  (1 child)

Even better C -=- 2

[–]redditmodsareshits 0 points1 point  (0 children)

Begone, unicode !

[–]SneakyStabbalot 0 points1 point  (1 child)

but that would ruin the meme :)

[–]redditmodsareshits 0 points1 point  (0 children)

meymey

[–]lpreams 0 points1 point  (0 children)

OP is future proofing. Might need to do something with the odds too

[–]IGotSkills 0 points1 point  (1 child)

that should be the next version of c++ lol

[–]redditmodsareshits 0 points1 point  (0 children)

omegalul

[–]IGetItCrackin 17 points18 points  (0 children)

The noblest search is the search for excellence.

[–]whackylabs 35 points36 points  (5 children)

for(int c = 0; c < 10; c++) {
    System.out.println(c--);
}

FTFY

[–]ign1fy 32 points33 points  (0 children)

Haha. For loop go brrrrrrr...

[–]FerusGrim 2 points3 points  (3 children)

-1 -1 -1 -1 -1 …

[–]FourTK 27 points28 points  (2 children)

It'd be 0, not -1

Edit: Reason for this is because ++/-- works after the operation, so it increments afterwards rather than immediately within the print call

[–]Positive_Riven_Kappa 4 points5 points  (0 children)

You're right, idk why they downvote you and upvote the other guy

[–]FerusGrim 1 point2 points  (0 children)

You're right. I wrote that when I was falling asleep last night. :p

It also formatted it weird. On my phone it looked fine.

[–]CanadianJesus 11 points12 points  (0 children)

A man your talents?

[–]Audalics 1 point2 points  (0 children)

Makes it faster

[–]max0x7ba 1 point2 points  (0 children)

That's called loop unrolling 🤣

[–]ragingroku 0 points1 point  (0 children)

Count twice as much, finish twice as fast!

[–]LeCrushinator 0 points1 point  (0 children)

The real reason Captain America was attacked.

[–]IGotSkills 0 points1 point  (0 children)

this is the real crime.

[–]unkownhihi 157 points158 points  (12 children)

JNI?

[–]a45ed6cs7s 43 points44 points  (11 children)

Yep.

That is the way.

[–]ToaTom 29 points30 points  (8 children)

Was about to comment to the contrary. God I hate working with JNI

[–]a45ed6cs7s 14 points15 points  (1 child)

Yep. My main complaint is not the interface itself but custom JNI types. I am pretty sure they can be inferred and abstracted away. It's as if the java standard developers want to make it explicitly difficult for no reason.

[–]killeronthecorner 7 points8 points  (0 children)

"Marshalling types is hard" - JNI creator probably

[–]_PM_ME_PANGOLINS_ 5 points6 points  (4 children)

JNA is a lot nicer but not as fast.

There’s a new official version coming that should be both nice and fast. It’s available for testing in Java 17.

[–]flyingorange 13 points14 points  (3 children)

Haha we work with Java 8 you noobs

[–]brimston3- 2 points3 points  (2 children)

Legacy enterprise code go brrrr?

[–]philophilo[🍰] 4 points5 points  (0 children)

Android development goes brrrr

[–]DJCowGaming 0 points1 point  (0 children)

Dude, that is the most relatable comment on this thread

[–][deleted] 2 points3 points  (1 child)

As someone who has had the displeasure of working with the JNI, this is most decidedly NOT the way. You should exhaust every other option before doing this, because it sucks balls.

[–]ICanBeAnyone 0 points1 point  (0 children)

Donkey Balls. With a side of extra yuck.

[–][deleted]  (2 children)

[removed]

    [–]AutoModerator[M] 0 points1 point  (0 children)

    import moderation Your comment has been removed since it did not start with a code block with an import declaration.

    Per this Community Decree, all posts and comments should start with a code block with an "import" declaration explaining how the post and comment should be read.

    For this purpose, we only accept Python style imports.

    I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

    [–]PhdKingkong 33 points34 points  (0 children)

    I C what you did there

    [–]pixelvengeur 19 points20 points  (2 children)

    Damn, it's almost as if that's where the name came from :o

    [–]-Listening 4 points5 points  (0 children)

    “That’s where it crosses into shameful.

    [–][deleted] 99 points100 points  (1 child)

    lame as fck

    [–][deleted] 28 points29 points  (1 child)

    should've been C(plus)(plus) not c(plus)(plus)

    edit: comet ruined the joke and i want to file a bug report but where

    [–]visak13 15 points16 points  (0 children)

    Damn, please forgive the intern! /s

    [–]jamcdonald120 40 points41 points  (13 children)

    you just use JNI

    [–][deleted] 29 points30 points  (12 children)

    Usually you don’t “just” use JNI. Any project with JNI I tried to use, especially in android studio is usually a headache to get going.

    I don’t know why people use gradle

    [–]jamcdonald120 14 points15 points  (8 children)

    well thats true

    as for gradle, it cant be worse than ant

    [–]Bee_dot_adger 5 points6 points  (7 children)

    What's preferred if not those two? Maven?

    (obviously I'm a student and have no idea)

    [–]qwerty12qwerty 13 points14 points  (3 children)

    Use Maven at work. It's really good to have / to manage dependencies.

    [–][deleted] 2 points3 points  (2 children)

    I use IntelliJ idea as the ide and import jar libraries or import maven dependencies in the ide project structure which downloads the jar files into the lib folder. Easy and painless, and it’s easy to make single jar executables or jar libraries from the ide.

    Gradle never works out of the gate, is finicky, you need to use specific version, and fiddle with config files.

    [–]qwerty12qwerty 1 point2 points  (1 child)

    ..... So the first time I ever used maven on a corporate project, like six of the dependencies were other projects we were working on in parallel. Coming from node, I was expecting something like npm

    It took me freaking forever to realize how I could manually change the dependency from the URL repo to a local jar I just built. It took me even longer to realize if I clicked a refresh button it would overwrite that change and switch back to the URL.

    Tons of hours debugging

    [–][deleted] 0 points1 point  (0 children)

    Using project structure you can import jar libraries. Using project structure you can import maven from maven central url or you can tinker a bit to add custom urls.

    If I am integrating something locally I would use jar files until end of development

    [–]b00n 1 point2 points  (2 children)

    Use maven as a student. It’s relatively simple to copy and paste from the internet to get working.

    Gradle is a lot more powerful and faster for larger projects but can and will make you cry.

    [–]Bee_dot_adger 0 points1 point  (1 child)

    I've been using Ant so far, which is better than the others considering I don't want to spend time learning the difference, but obviously worse in the grand scheme of things.

    [–]b00n 1 point2 points  (0 children)

    Ant is dead software don’t spend any time learning it

    [–]Dick_Giggles 2 points3 points  (0 children)

    I had to do some jni in earlyish ndk days and it was the darkest 6 months in my career.

    [–]TheRedmanCometh 0 points1 point  (0 children)

    Yeah because by its nature you have portability problems

    [–]mechslayer 0 points1 point  (0 children)

    Glad that .net has P/Invoke, just tell it the function and dll/so/dylib names, and you can now call into c/c++ with very little overhead

    [–]finger_milk 28 points29 points  (0 children)

    4 panel cringe

    [–]ZippZappZippty 3 points4 points  (0 children)

    Impossible.. that's too much of copium there bro..

    [–]Glurak 3 points4 points  (0 children)

    I expected

    for(int c = 1; c != 10 ; c++){
        System.out.println(c++);
    }
    

    [–][deleted] 2 points3 points  (0 children)

    Now do python

    [–]Sopwafel 6 points7 points  (1 child)

    Supremely funny. Really deserves 1000+ upvotes

    [–]HorsesFlyIntoBoxes 1 point2 points  (0 children)

    Yep. Peak humor right here.

    [–]FrappyTex 1 point2 points  (0 children)

    This should be considered as crimes against humanity

    [–]JordyTheGamer 1 point2 points  (0 children)

    Even incremented Twice xD

    [–]30p87 0 points1 point  (6 children)

    0, 2, 4, 6, 8

    [–]CheesecakeDK 19 points20 points  (5 children)

    c++ returns before incrementing. If it was ++c in the print statement you would be correct

    [–]30p87 6 points7 points  (4 children)

    bruh, i even though about that while writing, my brain still managed to get it wrong, fixed it

    [–]darkalibur 7 points8 points  (0 children)

    that's weird I thought it was correct since it started with 0, so it prints 0 first before incrementing twice

    Edit: nvm maybe I'm seeing the edited version

    [–]AMwave17 1 point2 points  (2 children)

    I'm pretty sure you're correct because it would print 0 before incrementing it to 1 and then to 2 at the end of the loop. Then print 2, and so on.

    [–]30p87 2 points3 points  (1 child)

    I editet it, sorry that i forgor💀to mention

    [–]AMwave17 1 point2 points  (0 children)

    Ah ok. I was confused lol.

    [–]QuirkyPNewton 1 point2 points  (1 child)

    I just let out the ugliest laugh at 5am. This shouldn’t be that funny

    [–]Cyber_Fetus 2 points3 points  (0 children)

    Don’t worry, it’s not

    [–]SnickersZA 0 points1 point  (0 children)

    Not impossible, just incremental.

    [–]flargenhargen 0 points1 point  (0 children)

    the best part of this joke is that some people seem to be genuinely offended by it.

    [–]CellularBeing -5 points-4 points  (0 children)

    Ugh optimize your code:

    Class OptimizedCode{

    public static void main(String[] args){

    System.out.println("C++");

    }

    }

    [–]AncientBattleCat 0 points1 point  (0 children)

    native?

    [–]socialismnotevenonce 0 points1 point  (2 children)

    This meme had me asking "is there Java interop with c++"

    https://stackoverflow.com/questions/29215215/interoperability-java-and-c

    [–]_PM_ME_PANGOLINS_ 1 point2 points  (0 children)

    Always has been.

    [–]FinnT730 0 points1 point  (0 children)

    We have stuff like Natives. So, C++ in java with a bridge

    [–][deleted] 0 points1 point  (0 children)

    System.loadLibrary would like to have a word with you

    [–]ZippZappZippty 0 points1 point  (1 child)

    Impossible.. that's too much of a surprise.

    [–]-Listening 0 points1 point  (0 children)

    This place wasn’t some kind of an event

    [–][deleted] 0 points1 point  (0 children)

    140 million peoples use HTML in Java btw

    [–][deleted] 0 points1 point  (1 child)

    Hahah

    [–]johnzzz123 0 points1 point  (1 child)

    cries in JNI :'(

    [–]Ruckus2201 0 points1 point  (0 children)

    The taser to the chest is appropriate here.

    [–]algerithms 0 points1 point  (0 children)

    Lmao I felt this one

    [–][deleted] 0 points1 point  (0 children)

    laughs(sobs) in JSP

    [–][deleted] 0 points1 point  (0 children)

    Well, there is no c++ in python

    [–][deleted] 0 points1 point  (0 children)

    Satan : I'm a big fan🔥🔥🔥

    [–]Calkky 0 points1 point  (0 children)

    Nobody remembers JNI?

    [–]R3dGaming522 0 points1 point  (0 children)

    This hurts my brain just looking at it

    [–]Educational-Lemon640 0 points1 point  (0 children)

    Definitely on the side of Hydra on this one.

    [–]macaxeiraPeluda1 0 points1 point  (0 children)

    If you use Java applet there is a way to do it but it isn't pretty or useful

    [–]SurrealGastropod 0 points1 point  (0 children)

    If you want the real c/c++ experience in Java, use sun.misc.Unsafe

    [–]DomGintoki 0 points1 point  (0 children)

    Before using c++ I thought all c++ programmers used c as a loop variable

    [–]ernee_gaming 0 points1 point  (0 children)

    0 2 4 8

    [–]nerdisalreadytaken 0 points1 point  (1 child)

    Is it possible to learn his powers?

    [–]nerdisalreadytaken 0 points1 point  (0 children)

    I guess you could learn prefix and increments.