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

I do this

Name: Anonymous 2016-11-17 14:54

return(EXIT_SUCCESS)

And I don't care if you don't like it. It doesn't violate the standard. All you return EXIT_SUCCESS jerks can suck it.

Name: Anonymous 2016-11-17 15:13

I actually do this:
return(((EXIT_SUCCESS)))
...and I don't care if you don't like it.

Name: Anonymous 2016-11-17 15:19

I do return(((atoi("EXIT SUCCESS"))));

It's equivalent on the systems I use.

Name: Anonymous 2016-11-17 20:56

I actually do this
return(((EXIT_SUCCESS_BERGSTEIN)))

Name: Anonymous 2016-11-17 21:41

I actually do this:
*
"GRUNNUR"
;

Name: Anonymous 2016-11-17 22:32

I do this:
#include "project.h"

STDSTART
string name = newArray(u8, 200);
print("What is your name?");
input("%s", name);
print("Hello %s!", name);
print("My favorite number is %d!", randInt(1,100));
free(name);
STDEND

Name: Anonymous 2016-11-18 0:49

>>6
ENTERPRISE GRADE

Name: Anonymous 2016-11-18 1:10

I actually do this:
#include "void.h"

Name: Anonymous 2016-11-18 1:52

>>8
void.h is deprecated.

Name: Anonymous 2016-11-18 2:32

>>8,9 Actually it is. Writing your own utility headers is the hip new thing(/sarcasm).
void.h was just a bunch of experimental code and macros that were used to quickly write some programs. I never expected to maintain it forever, it was purely pragmatic affair to increase productivity. The key insight from void.h is that you can create neat zero-cost abstractions with macros and _Generic.
Something like print(arg1,...) is extremely elegant way to call printf N times with each argument being processed to get its format type:
print(arg1,...) => printf(typeformat(arg1),arg1 ); printf(typeformat(arg2),arg2 );...N times (with amount of arguments deciding the amount of calls(by arg counter macro)
While in plain C you need to specify each type format in the format string and make sure its valid(correct # of args, spacing,etc)

Name: Anonymous 2016-11-18 7:07

Just check fucking dubs

Name: Anonymous 2016-11-18 7:40

>>10
I disagree they're zero-cost. complex preprocessor directives are not idiomatic C and you need to change your mindset and learn about wierd quirks that aren't present in plain C. IIRC the guy who wrote PuTTY also made a header that implemented control structures like foreach() with macros and if you looked at their definitions, it's pretty hard to guess what they do - you must really sit down and think about it because it looks different from how you do things in plain C and some of the stuff he puts there would be redundant and/or roundabout if it was not designed for automated expansion. then you have stuff like debugging macros which is just a pain in the ass.

basically, those abstractions are zero-cost if the only 'cost' you can think of is an execution time overhead. the actual cost is the difficulty of writing, maintaining and debugging, as well as the difficulty of understanding the code if you're not the one who wrote those macros. there's also a bit of a technical tradeoff is that complex macros mean bigger programs and longer compile times but this is likely not too noticeable in practice.

this doesn't mean that this sort of metaprogramming is pointless (although dynamic and/or functional languages are IMHO better for metaprogramming than C + text replacement: it's just more intuitive when you have things like lambda or eval). but there's always a cost.

Name: Anonymous 2016-11-18 8:41

>>12
These "although dynamic and/or functional languages" are not zero-cost - C macros are the lowest overhead that can exist.

The barrier to understanding esoteric macros is not that high, and once you grasp how it works(its basically merging symbols with ## plus __VA_ARGS__ expansion rules) you can decode anything you see.
The problem appears when you use deeply nested macros(only recently gcc has improved their debug display for nested macros) interacting with each other:
since they are not code GCC is unable to show what it sees as wrong macro expansion - it shows where it fails to compile the results of the macro(it does show the macros in descending order, but you already know what produces the code) since C text macros are purely symbolic transmutation of tokens.

it's just more intuitive when you have things like lambda
Does it occur to you that any function macro is a lambda inlined on the spot? Macros don't have any syntax restrictions of a lambdas, and can be passed to other macros as tokens:
foreach_macro(array,lambda_macro) expands to for() loop with lambda_macro being its inner content
I know C preprocessor is really primitive at what it does, but its not unintuitive: its simple, fast and doesn't burden the resulting code with abstraction layers.

Name: Anonymous 2016-11-18 9:21

Foreach macro are incredibly hard to understand
//I will manually explain how it works
//MapInline macro - map result of func to each array member
#define mapi(A,func) ({foreach(i,A)A[i]=func(A[i]);})

//foreach - create a loop for each member of array up to elms_##iter(unique in-loop identifier name)
//example result: for(u8 i=0,elms_i=10;i<elms_i;i++)
#define foreach(iter,arr) for(u8 iter=0,elms_##iter=elems(arr);iter<elms_##iter;iter++)

//elems - Get number of elements in array
#define elems(arg) (size(arg)/sizeof(arg[0]))

//size1 - a dirty hack to get object size, if size is not(void pointer size) its a true size of object(primitive or array), if its actually a pointer it gets the size from msize(malloc_size) assuming its a heap-allocated object
#define size1(arg1) ({u8 lensize=sizeof(arg1);\
once;\
if((lensize!=sizeof(vp)))break;\
if(isarray(arg1)|isbasic(arg1)){;break;};\
lensize=msize((vp)(u8)arg1);endonce;\
;lensize;})
//just apply size1 to all arguments and sum them
#define size(...) sum(apply(size1,__VA_ARGS__))
//typecheck if object is an array
#define isarray(x) typecheck(x,arraytypes)
#define isbasic(x) typecheck(x,basictypes)
#define basictypes u1,u2,u4,u8,s1,s2,s4,s8,c1,c4,uc4,f4,f8,f10
#define arraytypes u1[],u2[],u4[],u8[],s1[],s2[],s4[],s8[],c1[],c4[],uc4[],f4[],f8[],f10[]

//typecheck - sums to above 0 if true,0 if false
#define typecheck(x,args) sum(varapply(x,istype,args))
//sum - sum arguments
#define sum(...) (opapply( + ,original,__VA_ARGS__))

//below are expanded to one of 63 functions per arg count macro
//varapply - apply with extra common(var) argument before each arguments

//{varapply same as apply but var is used as first argument for func, func(commonvar,argN)

#define varapply3(var,func,arg1) func(var,arg1)
#define varapply4(var,func,arg1,...) func(var,arg1) ,_VFUNC(varapply,nargs(var,func,__VA_ARGS__))(var,func,__VA_ARGS__)
#define varapply5(var,func,arg1,...) func(var,arg1) ,_VFUNC(varapply,nargs(var,func,__VA_ARGS__))(var,func,__VA_ARGS__)
#define varapply6(var,func,arg1,...) func(var,arg1) ,_VFUNC(varapply,nargs(var,func,__VA_ARGS__))(var,func,__VA_ARGS__)
#define varapply7(var,func,arg1,...) func(var,arg1) ,_VFUNC(varapply,nargs(var,func,__VA_ARGS__))(var,func,__VA_ARGS__)
#define varapply8(var,func,arg1,...) func(var,arg1) ,_VFUNC(varapply,nargs(var,func,__VA_ARGS__))(var,func,__VA_ARGS__)
#define varapply9(var,func,arg1,...) func(var,arg1) ,_VFUNC(varapply,nargs(var,func,__VA_ARGS__))(var,func,__VA_ARGS__)

#define varapply10(var,func,arg1,...) func(var,arg1) ,_VFUNC(varapply,nargs(var,func,__VA_ARGS__))(var,func,__VA_ARGS__)
#define varapply11(var,func,arg1,...) func(var,arg1) ,_VFUNC(varapply,nargs(var,func,__VA_ARGS__))(var,func,__VA_ARGS__)
#define varapply12(var,func,arg1,...) func(var,arg1) ,_VFUNC(varapply,nargs(var,func,__VA_ARGS__))(var,func,__VA_ARGS__)
#define varapply13(var,func,arg1,...) func(var,arg1) ,_VFUNC(varapply,nargs(var,func,__VA_ARGS__))(var,func,__VA_ARGS__)
#define varapply14(var,func,arg1,...) func(var,arg1) ,_VFUNC(varapply,nargs(var,func,__VA_ARGS__))(var,func,__VA_ARGS__)
#define varapply15(var,func,arg1,...) func(var,arg1) ,_VFUNC(varapply,nargs(var,func,__VA_ARGS__))(var,func,__VA_ARGS__)
#define varapply16(var,func,arg1,...) func(var,arg1) ,_VFUNC(varapply,nargs(var,func,__VA_ARGS__))(var,func,__VA_ARGS__)
#define varapply17(var,func,arg1,...) func(var,arg1) ,_VFUNC(varapply,nargs(var,func,__VA_ARGS__))(var,func,__VA_ARGS__)
#define varapply18(var,func,arg1,...) func(var,arg1) ,_VFUNC(varapply,nargs(var,func,__VA_ARGS__))(var,func,__VA_ARGS__)
#define varapply19(var,func,arg1,...) func(var,arg1) ,_VFUNC(varapply,nargs(var,func,__VA_ARGS__))(var,func,__VA_ARGS__)

#define varapply20(var,func,arg1,...) func(var,arg1) ,_VFUNC(varapply,nargs(var,func,__VA_ARGS__))(var,func,__VA_ARGS__)
#define varapply21(var,func,arg1,...) func(var,arg1) ,_VFUNC(varapply,nargs(var,func,__VA_ARGS__))(var,func,__VA_ARGS__)
#define varapply22(var,func,arg1,...) func(var,arg1) ,_VFUNC(varapply,nargs(var,func,__VA_ARGS__))(var,func,__VA_ARGS__)
#define varapply23(var,func,arg1,...) func(var,arg1) ,_VFUNC(varapply,nargs(var,func,__VA_ARGS__))(var,func,__VA_ARGS__)
#define varapply24(var,func,arg1,...) func(var,arg1) ,_VFUNC(varapply,nargs(var,func,__VA_ARGS__))(var,func,__VA_ARGS__)
#define varapply25(var,func,arg1,...) func(var,arg1) ,_VFUNC(varapply,nargs(var,func,__VA_ARGS__))(var,func,__VA_ARGS__)
#define varapply26(var,func,arg1,...) func(var,arg1) ,_VFUNC(varapply,nargs(var,func,__VA_ARGS__))(var,func,__VA_ARGS__)
#define varapply27(var,func,arg1,...) func(var,arg1) ,_VFUNC(varapply,nargs(var,func,__VA_ARGS__))(var,func,__VA_ARGS__)
#define varapply28(var,func,arg1,...) func(var,arg1) ,_VFUNC(varapply,nargs(var,func,__VA_ARGS__))(var,func,__VA_ARGS__)
#define varapply29(var,func,arg1,...) func(var,arg1) ,_VFUNC(varapply,nargs(var,func,__VA_ARGS__))(var,func,__VA_ARGS__)

#define varapply30(var,func,arg1,...) func(var,arg1) ,_VFUNC(varapply,nargs(var,func,__VA_ARGS__))(var,func,__VA_ARGS__)
#define varapply31(var,func,arg1,...) func(var,arg1) ,_VFUNC(varapply,nargs(var,func,__VA_ARGS__))(var,func,__VA_ARGS__)
#define varapply32(var,func,arg1,...) func(var,arg1) ,_VFUNC(varapply,nargs(var,func,__VA_ARGS__))(var,func,__VA_ARGS__)
#define varapply33(var,func,arg1,...) func(var,arg1) ,_VFUNC(varapply,nargs(var,func,__VA_ARGS__))(var,func,__VA_ARGS__)
#define varapply34(var,func,arg1,...) func(var,arg1) ,_VFUNC(varapply,nargs(var,func,__VA_ARGS__))(var,func,__VA_ARGS__)
#define varapply35(var,func,arg1,...) func(var,arg1) ,_VFUNC(varapply,nargs(var,func,__VA_ARGS__))(var,func,__VA_ARGS__)
#define varapply36(var,func,arg1,...) func(var,arg1) ,_VFUNC(varapply,nargs(var,func,__VA_ARGS__))(var,func,__VA_ARGS__)
#define varapply37(var,func,arg1,...) func(var,arg1) ,_VFUNC(varapply,nargs(var,func,__VA_ARGS__))(var,func,__VA_ARGS__)
#define varapply38(var,func,arg1,...) func(var,arg1) ,_VFUNC(varapply,nargs(var,func,__VA_ARGS__))(var,func,__VA_ARGS__)
#define varapply39(var,func,arg1,...) func(var,arg1) ,_VFUNC(varapply,nargs(var,func,__VA_ARGS__))(var,func,__VA_ARGS__)

#define varapply40(var,func,arg1,...) func(var,arg1) ,_VFUNC(varapply,nargs(var,func,__VA_ARGS__))(var,func,__VA_ARGS__)
#define varapply41(var,func,arg1,...) func(var,arg1) ,_VFUNC(varapply,nargs(var,func,__VA_ARGS__))(var,func,__VA_ARGS__)
#define varapply42(var,func,arg1,...) func(var,arg1) ,_VFUNC(varapply,nargs(var,func,__VA_ARGS__))(var,func,__VA_ARGS__)
#define varapply43(var,func,arg1,...) func(var,arg1) ,_VFUNC(varapply,nargs(var,func,__VA_ARGS__))(var,func,__VA_ARGS__)
#define varapply44(var,func,arg1,...) func(var,arg1) ,_VFUNC(varapply,nargs(var,func,__VA_ARGS__))(var,func,__VA_ARGS__)
#define varapply45(var,func,arg1,...) func(var,arg1) ,_VFUNC(varapply,nargs(var,func,__VA_ARGS__))(var,func,__VA_ARGS__)
#define varapply46(var,func,arg1,...) func(var,arg1) ,_VFUNC(varapply,nargs(var,func,__VA_ARGS__))(var,func,__VA_ARGS__)
#define varapply47(var,func,arg1,...) func(var,arg1) ,_VFUNC(varapply,nargs(var,func,__VA_ARGS__))(var,func,__VA_ARGS__)
#define varapply48(var,func,arg1,...) func(var,arg1) ,_VFUNC(varapply,nargs(var,func,__VA_ARGS__))(var,func,__VA_ARGS__)
#define varapply49(var,func,arg1,...) func(var,arg1) ,_VFUNC(varapply,nargs(var,func,__VA_ARGS__))(var,func,__VA_ARGS__)
\
#define varapply50(var,func,arg1,...) func(var,arg1) ,_VFUNC(varapply,nargs(var,func,__VA_ARGS__))(var,func,__VA_ARGS__)
#define varapply51(var,func,arg1,...) func(var,arg1) ,_VFUNC(varapply,nargs(var,func,__VA_ARGS__))(var,func,__VA_ARGS__)
#define varapply52(var,func,arg1,...) func(var,arg1) ,_VFUNC(varapply,nargs(var,func,__VA_ARGS__))(var,func,__VA_ARGS__)
#define varapply53(var,func,arg1,...) func(var,arg1) ,_VFUNC(varapply,nargs(var,func,__VA_ARGS__))(var,func,__VA_ARGS__)
#define varapply54(var,func,arg1,...) func(var,arg1) ,_VFUNC(varapply,nargs(var,func,__VA_ARGS__))(var,func,__VA_ARGS__)
#define varapply55(var,func,arg1,...) func(var,arg1) ,_VFUNC(varapply,nargs(var,func,__VA_ARGS__))(var,func,__VA_ARGS__)
#define varapply56(var,func,arg1,...) func(var,arg1) ,_VFUNC(varapply,nargs(var,func,__VA_ARGS__))(var,func,__VA_ARGS__)
#define varapply57(var,func,arg1,...) func(var,arg1) ,_VFUNC(varapply,nargs(var,func,__VA_ARGS__))(var,func,__VA_ARGS__)
#define varapply58(var,func,arg1,...) func(var,arg1) ,_VFUNC(varapply,nargs(var,func,__VA_ARGS__))(var,func,__VA_ARGS__)
#define varapply59(var,func,arg1,...) func(var,arg1) ,_VFUNC(varapply,nargs(var,func,__VA_ARGS__))(var,func,__VA_ARGS__)

#define varapply60(var,func,arg1,...) func(var,arg1) ,_VFUNC(varapply,nargs(var,func,__VA_ARGS__))(var,func,__VA_ARGS__)
#define varapply61(var,func,arg1,...) func(var,arg1) ,_VFUNC(varapply,nargs(var,func,__VA_ARGS__))(var,func,__VA_ARGS__)
#define varapply62(var,func,arg1,...) func(var,arg1) ,_VFUNC(varapply,nargs(var,func,__VA_ARGS__))(var,func,__VA_ARGS__)
#define varapply63(var,func,arg1,...) func(var,arg1) ,_VFUNC(varapply,nargs(var,func,__VA_ARGS__))(var,func,__VA_ARGS__)
#define varapply64(var,func,arg1,...) func(var,arg1) ,_VFUNC(varapply,nargs(var,func,__VA_ARGS__))(var,func,__VA_ARGS__)

#define varapply(var,func,arg1,...) _VFUNC(varapply,nargs(var,func,arg1,__VA_ARGS__))(var,func,arg1,__VA_ARGS__)

//opapply - apply and insert operators(pasting OP between arguments) = func(arg1) operator func(arg2) ,etc
//OPAPPLY:same as apply but use custom "operator" glue macro instead of comma

//_VFUNC(pv, nargs(__VA_ARGS__))(__VA_ARGS__)
#define opapply3(operator,func,arg1) func(arg1)
#define opapply4(operator,func,arg1,...) func(arg1) operator _VFUNC(opapply,nargs(operator,func,__VA_ARGS__))(operator,func,__VA_ARGS__)
#define opapply5(operator,func,arg1,...) func(arg1) operator _VFUNC(opapply,nargs(operator,func,__VA_ARGS__))(operator,func,__VA_ARGS__)
#define opapply6(operator,func,arg1,...) func(arg1) operator _VFUNC(opapply,nargs(operator,func,__VA_ARGS__))(operator,func,__VA_ARGS__)
#define opapply7(operator,func,arg1,...) func(arg1) operator _VFUNC(opapply,nargs(operator,func,__VA_ARGS__))(operator,func,__VA_ARGS__)
#define opapply8(operator,func,arg1,...) func(arg1) operator _VFUNC(opapply,nargs(operator,func,__VA_ARGS__))(operator,func,__VA_ARGS__)
#define opapply9(operator,func,arg1,...) func(arg1) operator _VFUNC(opapply,nargs(operator,func,__VA_ARGS__))(operator,func,__VA_ARGS__)

#define opapply10(operator,func,arg1,...) func(arg1) operator _VFUNC(opapply,nargs(operator,func,__VA_ARGS__))(operator,func,__VA_ARGS__)
#define opapply11(operator,func,arg1,...) func(arg1) operator _VFUNC(opapply,nargs(operator,func,__VA_ARGS__))(operator,func,__VA_ARGS__)
#define opapply12(operator,func,arg1,...) func(arg1) operator _VFUNC(opapply,nargs(operator,func,__VA_ARGS__))(operator,func,__VA_ARGS__)
#define opapply13(operator,func,arg1,...) func(arg1) operator _VFUNC(opapply,nargs(operator,func,__VA_ARGS__))(operator,func,__VA_ARGS__)
#define opapply14(operator,func,arg1,...) func(arg1) operator _VFUNC(opapply,nargs(operator,func,__VA_ARGS__))(operator,func,__VA_ARGS__)
#define opapply15(operator,func,arg1,...) func(arg1) operator _VFUNC(opapply,nargs(operator,func,__VA_ARGS__))(operator,func,__VA_ARGS__)
#define opapply16(operator,func,arg1,...) func(arg1) operator _VFUNC(opapply,nargs(operator,func,__VA_ARGS__))(operator,func,__VA_ARGS__)
#define opapply17(operator,func,arg1,...) func(arg1) operator _VFUNC(opapply,nargs(operator,func,__VA_ARGS__))(operator,func,__VA_ARGS__)
#define opapply18(operator,func,arg1,...) func(arg1) operator _VFUNC(opapply,nargs(operator,func,__VA_ARGS__))(operator,func,__VA_ARGS__)
#define opapply19(operator,func,arg1,...) func(arg1) operator _VFUNC(opapply,nargs(operator,func,__VA_ARGS__))(operator,func,__VA_ARGS__)

#define opapply20(operator,func,arg1,...) func(arg1) operator _VFUNC(opapply,nargs(operator,func,__VA_ARGS__))(operator,func,__VA_ARGS__)
#define opapply21(operator,func,arg1,...) func(arg1) operator _VFUNC(opapply,nargs(operator,func,__VA_ARGS__))(operator,func,__VA_ARGS__)
#define opapply22(operator,func,arg1,...) func(arg1) operator _VFUNC(opapply,nargs(operator,func,__VA_ARGS__))(operator,func,__VA_ARGS__)
#define opapply23(operator,func,arg1,...) func(arg1) operator _VFUNC(opapply,nargs(operator,func,__VA_ARGS__))(operator,func,__VA_ARGS__)
#define opapply24(operator,func,arg1,...) func(arg1) operator _VFUNC(opapply,nargs(operator,func,__VA_ARGS__))(operator,func,__VA_ARGS__)
#define opapply25(operator,func,arg1,...) func(arg1) operator _VFUNC(opapply,nargs(operator,func,__VA_ARGS__))(operator,func,__VA_ARGS__)
#define opapply26(operator,func,arg1,...) func(arg1) operator _VFUNC(opapply,nargs(operator,func,__VA_ARGS__))(operator,func,__VA_ARGS__)
#define opapply27(operator,func,arg1,...) func(arg1) operator _VFUNC(opapply,nargs(operator,func,__VA_ARGS__))(operator,func,__VA_ARGS__)
#define opapply28(operator,func,arg1,...) func(arg1) operator _VFUNC(opapply,nargs(operator,func,__VA_ARGS__))(operator,func,__VA_ARGS__)
#define opapply29(operator,func,arg1,...) func(arg1) operator _VFUNC(opapply,nargs(operator,func,__VA_ARGS__))(operator,func,__VA_ARGS__)

#define opapply30(operator,func,arg1,...) func(arg1) operator _VFUNC(opapply,nargs(operator,func,__VA_ARGS__))(operator,func,__VA_ARGS__)
#define opapply31(operator,func,arg1,...) func(arg1) operator _VFUNC(opapply,nargs(operator,func,__VA_ARGS__))(operator,func,__VA_ARGS__)
#define opapply32(operator,func,arg1,...) func(arg1) operator _VFUNC(opapply,nargs(operator,func,__VA_ARGS__))(operator,func,__VA_ARGS__)
#define opapply33(operator,func,arg1,...) func(arg1) operator _VFUNC(opapply,nargs(operator,func,__VA_ARGS__))(operator,func,__VA_ARGS__)
#define opapply34(operator,func,arg1,...) func(arg1) operator _VFUNC(opapply,nargs(operator,func,__VA_ARGS__))(operator,func,__VA_ARGS__)
#define opapply35(operator,func,arg1,...) func(arg1) operator _VFUNC(opapply,nargs(operator,func,__VA_ARGS__))(operator,func,__VA_ARGS__)
#define opapply36(operator,func,arg1,...) func(arg1) operator _VFUNC(opapply,nargs(operator,func,__VA_ARGS__))(operator,func,__VA_ARGS__)
#define opapply37(operator,func,arg1,...) func(arg1) operator _VFUNC(opapply,nargs(operator,func,__VA_ARGS__))(operator,func,__VA_ARGS__)
#define opapply38(operator,func,arg1,...) func(arg1) operator _VFUNC(opapply,nargs(operator,func,__VA_ARGS__))(operator,func,__VA_ARGS__)
#define opapply39(operator,func,arg1,...) func(arg1) operator _VFUNC(opapply,nargs(operator,func,__VA_ARGS__))(operator,func,__VA_ARGS__)

#define opapply40(operator,func,arg1,...) func(arg1) operator _VFUNC(opapply,nargs(operator,func,__VA_ARGS__))(operator,func,__VA_ARGS__)
#define opapply41(operator,func,arg1,...) func(arg1) operator _VFUNC(opapply,nargs(operator,func,__VA_ARGS__))(operator,func,__VA_ARGS__)
#define opapply42(operator,func,arg1,...) func(arg1) operator _VFUNC(opapply,nargs(operator,func,__VA_ARGS__))(operator,func,__VA_ARGS__)
#define opapply43(operator,func,arg1,...) func(arg1) operator _VFUNC(opapply,nargs(operator,func,__VA_ARGS__))(operator,func,__VA_ARGS__)
#define opapply44(operator,func,arg1,...) func(arg1) operator _VFUNC(opapply,nargs(operator,func,__VA_ARGS__))(operator,func,__VA_ARGS__)
#define opapply45(operator,func,arg1,...) func(arg1) operator _VFUNC(opapply,nargs(operator,func,__VA_ARGS__))(operator,func,__VA_ARGS__)
#define opapply46(operator,func,arg1,...) func(arg1) operator _VFUNC(opapply,nargs(operator,func,__VA_ARGS__))(operator,func,__VA_ARGS__)
#define opapply47(operator,func,arg1,...) func(arg1) operator _VFUNC(opapply,nargs(operator,func,__VA_ARGS__))(operator,func,__VA_ARGS__)
#define opapply48(operator,func,arg1,...) func(arg1) operator _VFUNC(opapply,nargs(operator,func,__VA_ARGS__))(operator,func,__VA_ARGS__)
#define opapply49(operator,func,arg1,...) func(arg1) operator _VFUNC(opapply,nargs(operator,func,__VA_ARGS__))(operator,func,__VA_ARGS__)
\
#define opapply50(operator,func,arg1,...) func(arg1) operator _VFUNC(opapply,nargs(operator,func,__VA_ARGS__))(operator,func,__VA_ARGS__)
#define opapply51(operator,func,arg1,...) func(arg1) operator _VFUNC(opapply,nargs(operator,func,__VA_ARGS__))(operator,func,__VA_ARGS__)
#define opapply52(operator,func,arg1,...) func(arg1) operator _VFUNC(opapply,nargs(operator,func,__VA_ARGS__))(operator,func,__VA_ARGS__)
#define opapply53(operator,func,arg1,...) func(arg1) operator _VFUNC(opapply,nargs(operator,func,__VA_ARGS__))(operator,func,__VA_ARGS__)
#define opapply54(operator,func,arg1,...) func(arg1) operator _VFUNC(opapply,nargs(operator,func,__VA_ARGS__))(operator,func,__VA_ARGS__)
#define opapply55(operator,func,arg1,...) func(arg1) operator _VFUNC(opapply,nargs(operator,func,__VA_ARGS__))(operator,func,__VA_ARGS__)
#define opapply56(operator,func,arg1,...) func(arg1) operator _VFUNC(opapply,nargs(operator,func,__VA_ARGS__))(operator,func,__VA_ARGS__)
#define opapply57(operator,func,arg1,...) func(arg1) operator _VFUNC(opapply,nargs(operator,func,__VA_ARGS__))(operator,func,__VA_ARGS__)
#define opapply58(operator,func,arg1,...) func(arg1) operator _VFUNC(opapply,nargs(operator,func,__VA_ARGS__))(operator,func,__VA_ARGS__)
#define opapply59(operator,func,arg1,...) func(arg1) operator _VFUNC(opapply,nargs(operator,func,__VA_ARGS__))(operator,func,__VA_ARGS__)

#define opapply60(operator,func,arg1,...) func(arg1) operator _VFUNC(opapply,nargs(operator,func,__VA_ARGS__))(operator,func,__VA_ARGS__)
#define opapply61(operator,func,arg1,...) func(arg1) operator _VFUNC(opapply,nargs(operator,func,__VA_ARGS__))(operator,func,__VA_ARGS__)
#define opapply62(operator,func,arg1,...) func(arg1) operator _VFUNC(opapply,nargs(operator,func,__VA_ARGS__))(operator,func,__VA_ARGS__)
#define opapply63(operator,func,arg1,...) func(arg1) operator _VFUNC(opapply,nargs(operator,func,__VA_ARGS__))(operator,func,__VA_ARGS__)
#define opapply64(operator,func,arg1,...) func(arg1) operator _VFUNC(opapply,nargs(operator,func,__VA_ARGS__))(operator,func,__VA_ARGS__)

#define opapply(operator,func,...) _VFUNC(opapply,nargs(operator,func,__VA_ARGS__))(operator,func,__VA_ARGS__)

//find token that equals to number of arguments
#define nargs(...) NARG_I_(__VA_ARGS__,reverse_push_seq_N)
//push array of (Real_Args,63_Counter_args)
#define NARG_I_(...) ARG_N(__VA_ARGS__)
//Arguments Count returned as N(position shifted by length of Real_Args(neat hack)
#define ARG_N( \
_1, _2, _3, _4, _5, _6, _7, _8, _9,_10, \
_11,_12,_13,_14,_15,_16,_17,_18,_19,_20, \
_21,_22,_23,_24,_25,_26,_27,_28,_29,_30, \
_31,_32,_33,_34,_35,_36,_37,_38,_39,_40, \
_41,_42,_43,_44,_45,_46,_47,_48,_49,_50, \
_51,_52,_53,_54,_55,_56,_57,_58,_59,_60, \
_61,_62,_63,N,...) N
//the position tokens(numbers) pushed in reverse to get arg_count
#define reverse_push_seq_N \
63,62,61,60, \
59,58,57,56,55,54,53,52,51,50, \
49,48,47,46,45,44,43,42,41,40, \
39,38,37,36,35,34,33,32,31,30, \
29,28,27,26,25,24,23,22,21,20, \
19,18,17,16,15,14,13,12,11,10, \
9,8,7,6,5,4,3,2,1,0

// general definition for any function name
//proxy is just fluff to prevent preprocessor not expanding merge in nested macros, merge is pasting func##arg_count
#define _VFUNC(name, n) proxy(merge)(name, n)
#define VFUNC(func, ...) _VFUNC(func, nargs(__VA_ARGS__))(__VA_ARGS__)

Name: Anonymous 2016-11-18 9:25

#define merge1(x,y) x##y
#define merge2(x,y) merge1(x,y)
#define merge3(x,y) merge2(x,y)

#define merge(x,y) merge2(x,y)
//force to expand N layers
#define expand(...) __VA_ARGS__
#define expand2(...) expand(expand(expand(__VA_ARGS__)))
#define expand3(...) expand2(expand2(expand2(__VA_ARGS__)))
#define expand4(...) expand3(expand3(expand3(__VA_ARGS__)))
#define expand5(...) expand4(expand4(expand4(__VA_ARGS__)))
//force to evaluate function multiple times
#define recur(...) expand5(expand5(expand5(__VA_ARGS__)))

#define proxy recur

Name: Anonymous 2016-11-18 10:12

>>14
That's surprisingly elegant.

Name: Anonymous 2016-11-18 10:22

Name: Anonymous 2016-11-18 11:09

>>13
These "although dynamic and/or functional languages" are not zero-cost - C macros are the lowest overhead that can exist.

I'm not arguing that dynamic languages are zero-cost. I'm arguing that C macros are not zero-cost. it's just that the cost is different: performance on one side, ease of writing/reading/debugging/maintaining code on the other. performance is not always the thing you care about the most, it depends on your requirements.

this is my problem with C/Pascal/Fortran/Assembly evangelists: they assume that performance is always the most important thing. sometimes it is, but not always.

anyway, assembler (e.g. FASM) macros have probably less overhead than C macros, but that's just me being nitpicky.

>>14
thanks for the explanation. two questions:
1. is there a way to do that in standards-conforming (no GNU extensions) way?
2. there's a lot of boilerplate here. couldn't we generate varapply/opapply macros automatically?

Name: Anonymous 2016-11-18 11:32

1. is there a way to do that in standards-conforming (no GNU extensions) way?
GCC will exist since linux and most of open-source depending on it. Why you hate GNU/Freedom?
2. there's a lot of boilerplate here. couldn't we generate varapply/opapply macros automatically?
Unfortunately, no.
1.C preprocessor forbids recursion and attempts to circumvent it result in slow processing and inability to nest anything safely see http://stackoverflow.com/questions/12447557/can-we-have-recursive-macros
2. Inability to refer to concrete #place of argument in arg manipulation code. Recursion makes all #numplaces equal.

Name: Anonymous 2016-11-18 11:39

>>19
GCC will exist since linux and most of open-source depending on it. Why you hate GNU/Freedom?
it's not about hate, it's about portability. I generally prefer writing standards-conforming code than implementation-specific one, independent of language I'm using. a key thing to remember is that you're not always writing a code for yourself: in a 1000 years, another /prog/rider might want to compile it on a 4678-bit quantum microcontroller running NeoTempleOS.
C preprocessor forbids recursion and attempts to circumvent it result in slow processing and inability to nest anything safely
how about more powerful text-replacement macro languages? have you tried M4?

Name: Anonymous 2016-11-18 13:05

This thread got AIDS.

Name: Anonymous 2016-11-18 13:05

>>21
this thread got dubs

Name: Anonymous 2016-11-18 13:08

>>20
I prefer built-in language features - "in a 1000 years, another /prog/rider might want to compile it on a 4678-bit" m4 is likely to change faster than C and GNU standard of the time. It could be abandoned in favor of competing tools easily, while gigabytes of C code will require maintenance and backward compatibility for the next few centuries.
how about more powerful text-replacement macro languages?
I'm researching D template mixins right now. Although D doesn't seem to be a C replacement it has similar speed and low-level access (bithacks,pointers,), LDC actually won a few benchmarks.

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