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

Vector valued functions

Name: Anonymous 2014-06-12 23:50

Fuck lists and their overhead. I just want an extension to C that lets me return vectors. Not classes, not structs, and nothing involving preprocessor shit either. Something like:
<int, int> divr(int a, int b){
return < a / b, a % b >;
}
int main(int asdfasdf, char ** qwerqwe){
int touhous = 5, men = 12;
int eachSucked, unsucked;
<eachSucked, unsucked> = divr(men, touhous);
printf("Each of the %d touhous sucked %d cocks, and there were %d left unsucked", touhous, eachSucked, unsucked);
return 0;
}

which would compile to something simple, like:divr:
pop eax
pop ebx
push edx
xor edx, edx
idiv ebx
mov ebx, edx
pop edx
push ebx
push eax
ret
main:
touhous dd 5
men dd 12
eachSucked dd ?
unsucked dd ?
push touhous
push men
jmp divr
pop [eachSucked]
pop [unsucked]
;; blah blah blah, printf goes here

Isn't that much more elegant that a nasty list every time where things have to be inserted or initialized? Oh, and if you don't need a return value, <a,b,NULL, c> will compile the unneeded return value out, or at least discard the result.

Name: Anonymous 2014-06-13 15:57

>>4
Typing. What if I wanted to return <int, float, char *>? The best I could do is
enum type{INT, FLOAT, CHARP};
struct __ret{void * data; enum type thisType};
struct __ret * funct(...){
int a = 1402624235; float b = 2.76; char c[] = "Lolies[i]![/i]";
struct __ret * ret = (struct __ret*) malloc(3 * sizeof(struct __ret));
ret[0].data = &a; ret[1].data = &a; ret[2].data = &a;
ret[0].data = INT; ret[0].data = FLOAT; ret[0].data = CHARP;
return 0;
}

Does that look good to you? Might as well just use an untyped list.

>>5
No, no, NO. None of that `put output in one of the parameters' shit. The only valid case for shit like that is maybe something like scanf(), but I suspect better solutions to that as well.

>>6
Well, I made this post with static (or at least deterministic at compile-time) sizes for the return vectors.

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