Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

C++ is awesome!

Name: Anonymous 2006-11-06 18:09

(a<b?a:b<c?b:c) = val();

Name: Anonymous 2006-11-06 18:23

another one:

(-42)[p] = 0;

Name: Anonymous 2006-11-06 18:52

>>2

that actually works??

Name: Anonymous 2006-11-06 18:52

What the fuck.

I've been using and studying C++ for almost 10 years now and I've never seen shit like this.

Name: Anonymous 2006-11-06 18:54

>>4
With C++, ANYTHING is possible!

Name: Anonymous 2006-11-06 19:27

o rly?

Show me a container class that can safely store different-type objects safely and without leaks... a heterogenous array, if you want to call it that.

Name: Anonymous 2006-11-07 1:34

>>6
std::vector<std::pair<type_enum, void*> >

am i rite!!!?

Name: Anonymous 2006-11-07 2:20

(-42)[p] = 0;
gets compiles to:
mov dword ptr [eax-0A8h],      0
wtf?

Name: Anonymous 2006-11-07 4:09

>>7

I considered doing that but it just seems sloppy.  It looks like it'd work, but somewhere you'll have to write a winding, thick forest of if or switch/case statements.  And excessive branching can really suck balls on some processors (lol Pentium 4 lol).

Although that's probably about as "neat" as you can get in C++, I guess... :/

Name: Anonymous 2006-11-07 5:03

>>8

eax is p

-0A8h is the hex value for -42 multiplied by 4 (the size of an int)

Name: Anonymous 2006-11-07 11:19

>>9

It does work. That is essentially the idea behind variant types.

Name: Anonymous 2006-11-10 3:04

>>9

I thought P4's crappy branching was one of the reasons the "branch prediction" technology in Intel's new processors kicks so much ass.

Name: Anonymous 2006-11-10 19:16

>>12
Netburst P4's have this "feature" due to the xbox-hueg long pipeline where one branch prediction miss costs you about twenty five cycles. That's on a Prescott, mind, it's like eighteen on Northwoods and Willamettes.

Unsurprisingly then the main speed boost from HyperThreading comes from being able to run the other thread while one suffers from a branch misprediction. Goodbye mainstream code performance.

NetBurst was pretty cool though if you first spent about a week coming up with an optimized routine to do something that you'd like. Kind of like an extremely well hidden DSP mode, only you need to do 128-bit wide integer SIMD stuff and no branching to get at it.

Name: Anonymous 2006-11-11 16:30

#define QUESTION (2b) || !(2b)

Name: Anonymous 2006-11-12 14:19

/(2b)||!b{2}/

Name: Anonymous 2006-11-12 14:41

>>14

Old, lame C joke is old and lame.

Name: Anonymous 2007-07-16 5:44 ID:WZdiXT6+

>>3
yes it works, the compiler sees it as *(p-42)
notice that in pointer arithmetic p - n really means p - ((n)*sizeof(*p))

Name: Anonymous 2007-07-16 5:53 ID:Heaven

>>17
Do you really think he still cares?

Name: Anonymous 2007-07-16 6:25 ID:BgKz3ekV

>>4,6-7
This is why C++ is a bad language.

>>9,12-13
You don't worry about that. OMG CFLAGS SUPER OPTIMIZED VEGETA WHAT DOES CPUID SAY ABOUT THE CPU CYCLES OMG ITS OVER NINE THOUSAND!

Name: Anonymous 2007-07-16 6:37 ID:eXsXQjZ9

>>19
You don't worry about that.

Name: Anonymous 2007-07-16 6:48 ID:Heaven

>>19
sounds to me like someone with a slow OS

Name: Anonymous 2007-07-16 17:37 ID:4NnK74Kh

obfuscation is ohsome

Name: Anonymous 2007-07-16 18:51 ID:J2sFyyfu

>>1
That isn't actually too hard to understand

Name: Anonymous 2007-07-16 19:00 ID:1Qg4jL4B

char *foo = (char[52]){0,};

of course, this also works in C99 where it is more cool.

Name: Anonymous 2007-07-16 19:01 ID:1Qg4jL4B

>>24
it's also a cool alternative to

char *foo = new char[52];

when you can't be arsed deleting/freeing it after you've used it. (happens at the end of the scope)

Name: Anonymous 2007-07-17 2:39 ID:Heaven

>>24
it actually works ONLY in c99

Name: Anonymous 2007-07-17 15:53 ID:3FwML6th

>>24-26
No.

char *foo = malloc(sizeof(char) * 52);

Stupid C++ programmers.

Name: Anonymous 2007-07-17 16:05 ID:6hM4VBlk

>>26
no, it works in C++ and c99, you know, 'cause we happened to be DISCUSSING C++.

>>27
char *foo = (char[52]){0,};

works in C99 kthx

Name: Anonymous 2007-07-17 16:24 ID:gcQ4l5vZ

Also:

if(a-2)

instead of

if(a!=2)

Name: Anonymous 2007-07-17 16:56 ID:OqFClqyH

>>29
What the fuck. Gento went that way ------> (out of /prog), now GTFO.

Name: Anonymous 2007-07-17 17:28 ID:uU2y6e+u

>>29
The first statement would get compiled to something like:
mov eax, [a]
sub eax, 2
test eax, eax
jne cond_false

The second gets compiled to:
cmp [a], 2
jne cond_false

Tell me, which one do you think is more efficient?

Name: Anonymous 2007-07-17 17:29 ID:uU2y6e+u

Additionally, the first of the statements lends itselfs to branch mispredictions, potentially making it slower for the CPU to pipeline the correct instructions.

Name: Anonymous 2007-07-17 18:00 ID:kKJBBW+y

if(a^=2) a^=1;

or

a^=a==2?a:3;

?

Name: Anonymous 2007-07-17 18:18 ID:Heaven

>>33
(a^=2)&&(a^=1);

Name: Anonymous 2007-07-18 3:08 ID:3a/FupcC

>>28
[ ]ANSI C
[ ]GTFO

THE CHOICE IS YOURS, SIR.

Name: Anonymous 2007-07-18 3:21 ID:Heaven

ISO > ANSI

Name: Anonymous 2007-07-18 4:34 ID:Heaven

>>27
You're doing it wrong
char *foo = malloc(sizeof(*foo) * n);
Also, YOU DON'T NEED TO MULTIPLY IT WITH sizeof(char), because that is guaranteed to be 1.
A char represents a byte.

Name: Anonymous 2007-07-18 4:42 ID:yz7Aoeaz

>>3
According to the Standard, a[b] is the same as b[a] which both are just syntactic sugar for *(a + b)
So: a[10] is *(a + 10) and 10[a] is *(10 + a) which are both the same thing.

Name: Anonymous 2007-07-18 4:45 ID:Heaven

>>37
If I remember the standard correctly, a character is AT LEAST a byte, but is in fact up to the implementation what the actual size is (depending on architecture and whatnot). Of course, it's been a while since I've looked at the standard, so I may be wrong.

Name: Anonymous 2007-07-18 4:56 ID:Heaven

>>25
Alternative, sure, but not the same. The (char[52]){0,} trick, i believe, would be placed on the stack, the new char[52] on the heap. Minor difference.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List