>>4 C functions don't validate input. strlen, strcat, and atoi will all usually segfault if you pass a bad string. The onus is on the caller to check inputs.
>>6 It's literally impossible to validate a C string without also passing an integer length (basically reinventing C++ std::string in a shittier more verbose way).
There is no guarantee that it's even possible for the calling code to validate it. E.g., argv[i] doesn't provide a length and many libraries follow that tradition.
Name:
Anonymous2018-02-23 9:28
loeb :: Functor f => f (f a -> a) -> f a loeb x = go where go = fmap ($ go) x
Name:
Anonymous2018-02-23 10:14
#include "void.h" //gist.github.com/FrozenVoid/87e6ad6212ac9ce496e0#file-void-h" STDSTART /* advanced anaphoric macro stolen from LISP wizards (defmacro aif (test-form then-form &optional else-form) `(let ((it ,test-form)) (if it ,then-form ,else-form))) (aif (+ 2 7) (format nil "~A does not equal NIL." it) (format nil "~A does equal NIL." it)) ;; ? "9 does not equal NIL." */ #define aif(expr,action1,action2) ({auto master_programmer_secret_storage_device=expr;/*very advanced and known only to LISP wizards*/;\ if(0!=master_programmer_secret_storage_device/*powerful lambda-calculus mathemathics, you won't understand*/){action1;}else{/*extremely esoteric and arcane secondary path*/action2;};/*we don't return nothing, because the secret of master_programmer_secret_storage_device must be kept */;}) aif(2+7,p(master_programmer_secret_storage_device,"does not equal NULL."),p(master_programmer_secret_storage_device,"does equal NULL."));//p prints arguments to stdout or FILE* see textio.h https://gist.github.com/FrozenVoid/87e6ad6212ac9ce496e0 aif(0+0+1-2+1,p(master_programmer_secret_storage_device,"does not equal NULL."),p(master_programmer_secret_storage_device,"does equal NULL."));
STDEND
Name:
Anonymous2018-02-23 10:15
>>10 FrozenAnus is back? I hope he checks my repeating digits
>>8 Well atof() could at least check for a NULL and set errno instead of segfaulting. I get that in C, you don't pay for what you don't need. Put adding a couple of instructions doesn't seem like a big deal for a function that already has a large number of instructions.
void fizzbuzz(int a, int b, int count){ int i; for(i=0;i<=count;i++){ if( ! ((i%a==0?printf("fizz"):0)|(i%b==0?printf("buzz"):0)) ){ printf("%d",i); } printf("\n"); } }
Name:
Anonymous2018-03-20 22:14
>>28 now do it with no conditionals like the guy from old /prog/
Name:
Anonymous2018-03-21 1:31
int main(int argc, char *argv[]);{ printf("fizzbuzz\n1\nfizz\n3\nfizz\nbuzz\nfizz\n7\nfizz\n9\nfizzbuzz\n11\nfizz\n13\nfizz\nbuzz\nfizz\n17\nfizz\n19\nfizzbuzz\n21\nfizz\n23\nfizz\nbuzz\nfizz\n27\nfizz\n29\nfizzbuzz\n31\nfizz\n33\nfizz\nbuzz\nfizz\n37\nfizz\n39\nfizzbuzz\n41\nfizz\n43\nfizz\nbuzz\nfizz\n47\nfizz\n49\nfizzbuzz\n51\nfizz\n53\nfizz\nbuzz\nfizz\n57\nfizz\n59\nfizzbuzz\n61\nfizz\n63\nfizz\nbuzz\nfizz\n67\nfizz\n69\nfizzbuzz\n71\nfizz\n73\nfizz\nbuzz\nfizz\n77\nfizz\n79\nfizzbuzz\n81\nfizz\n83\nfizz\nbuzz\nfizz\n87\nfizz\n89\nfizzbuzz\n91\nfizz\n93\nfizz\nbuzz\nfizz\n97\nfizz\n99\nfizzbuzz\n" }
Name:
Anonymous2018-03-21 6:18
>>10 #include "void.h"// gist.g ith ub.com /Fro zenV oid /87 e6 ad6 21 2a c9 ce4 9 6e0 # fi l e-void - h "S T DS T ART/*a d v a n ced ana ph o ri cm acr os to le n fr omL I SP wi za rd s ( d e fm a c r o aif (tes t- formt he n- fo r m& opt ionale l se -fo rm)`( let ((it,t est-f or m )) (if it,the n- for m,els e-form)))(aif (+27)(fo rm at n il" ~Ad oes notequalNI L."it) (fo rmatnil" ~Adoeseq u a l NIL ."it) );; ? "9do e snotequalN IL."*/#de fineaif(e xpr , a cti o n1,acti o n2)({au t omaste r_prog r amm er_secret_s t o rage_de vice= expr ;/*veryadva n ce d a ndknownonly toLISPwiza rds*/;if( 0!= ma s t er _pr ogr amm er_sec re t_ sto r a ge _d ev ice/*po we r fulla m bd a- ca lculusma th e mathi cs, you won 'tu nde r st and * /){ action1;}e lse{/*ext re me ly es o t er i ca nd ar c a ne s ec on da ry p a t h* / ac ti o n 2; };/*wedon't r e t ur n n ot h in g,b ec au s e th ese c r et of m as t e r_ pr og ra m mer _ se cr e t_st o rage_dev ic em ustbek e pt * / ;} )aif (2 + 7,p(master_p rog ram mer_secret_s to rage_de vi ce,"doe s notequalNULL."),p( master_programme r_ s ec ret_ st orage_device,"doesequalNULL."));//pprintsargumentstostd ou torFI L E* seet extio.hhttps://gist. github.com/FrozenVoid/ 8 7e6 ad 62 12 ac9ce496e0aif(0+0+1-2+1,p(ma ster_programmer_secr et_ st or a ge _device,"doesno tequalNUL L."),p(master_progr amme r _secret _s torage_device,"d oesequal NULL."));#inclu de" v oi d.h"//gi st.github.com/Fro zenVoid /87e6ad6212ac9ce 496e0#f i le- v oid-h"ST DSTART/*advanced anaphoric macrostolenfr omLISPwiza rds(def ma croaif(test-f ormthen-f orm&optionalelse-fo rm)`(le t(( i t,t est-form) )(ifit,then-form,else-f orm)))(aif(+27)(f orma tn il" ~A doe sno tequalNIL."it)(formatnil"~Ad oesequalNIL."it));;?"9 doesn ot equ alNIL."*/#defineaif(expr, a ction1,action2)({automaste r _ prog rammer_secret_storage_ de vice=expr;/*verya d vanced andkn ownon ly toLISPwizards*/;if (0!= ma ster_progra mm er_sec ret _s torage_device/ *p owe rfulla m bd a- ca l culusmathe ma thi cs,you wo
Name:
not >>282018-03-21 8:22
>>29 look ma, no ifs! #include <stdlib.h> #include <stdio.h>
short anus_device;
void printnum(int c){ switch(anus_device){ case 0: printf("%d",c); case 1: return; } }
void (*fizz[3])(int c) = {fizz_f, nop, nop}; void (*buzz[5])(int c) = {buzz_f, printnum, printnum, printnum, printnum};
int main(int argc, char **argv){ int i, n; switch(argc){ case 2: if(argc < 2) return -1; n = atoi(argv[1]); for(i = 0; i < n; i++){ anus_device = 0; (*fizz[i%3])(i); (*buzz[i%5])(i); puts(""); } default: return argc - 2; } }
Name:
Anonymous2018-03-21 8:24
look ma, dubs!
Name:
Anonymous2018-03-21 9:43
>>32 here's a (quick and dirty, plz no bully c*dder) version without ifs, loops and switches, just arrays of pointers and unconditional goto - but it's not portable (linux only) #include <stdlib.h> #include <stdio.h> #include <unistd.h>
>>42 Hope you didn't waste your precious work/neet time
Name:
Anonymous2018-03-21 14:43
I wasn't doing anything important anyway. also, check'em
Name:
Anonymous2018-03-21 16:37
There exist only 4 unary operations on binary input: invert (A->!A), maintain (A->A), nullify (A->0), validate (A->1). Yet, nullify and validate can be thought of as nullary operations, merely inherited into unary space. Likewise, in binary operations, analogues to the (strictly) unaries exist, like maintain first (A,B->A), maintain second (A,B->B), invert first (A,B->!A) and invert second (A,B->!B).
>>46 ackchyually, switch is more like a computed goto (unfortunately, C lacks true computed goto). but I knew that someone will complain about it, that's why I made >>34. it even validates command-line arguments without conditionals!
>>8 There's a definition for the max length of *argv though, so I'm not sure that's a good example.
Name:
Anonymous2018-04-02 11:14
A script for copying favorited photos from your iOS device #!/bin/sh ## https://brew.sh on macOS # brew install libimobiledevice # brew cask install osxfuse # brew install ifuse ## or compile from http://www.libimobiledevice.org for Linux and Windows ## plug in your iOS device ## give your computer access # idevicepair pair ## mount your iOS device's filesystem # ifuse ~/iPhone