Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I am the target audience. I get exactly what he’s going for but found a different gripe.

I really dislike his coding style! It’s written to be “short” in favor of clear. I see what the code does, but not necessarily his intent.

  void*page_alloc(unsigned long long bytes) {
  void *x;
  for(;;) {
    x = mmap(0, bytes, PROT_READ|PROT_WRITE, MAP_ANONYMOUS|MAP_PRIVATE, -1, 0);
    if(x != MAP_FAILED) return x;
    out_of_memory();
  }
}

For embedded I stoped using “unsigned long long” in favor of uint64_t. He spends all those extra characters but can’t put a space in the void pointer function definition?



Apologies! I usually typedef long long J;typedef unsigned long long U; and that makes it a bit shorter, but I wanted each example to compile, and not to get bogged down on typedefs.


If you use this kind of typedefs, most people reading your code will kind of hate you... either that or you're targeting the Internationl Obfuscated C Code Contents [1].

[1] - https://www.ioccc.org/


Perhaps this might help explain their reasoning: https://news.ycombinator.com/item?id=22010590


I didn’t downvote you, but your link contained this... and I considered it.

  ZI http(I d,I f,C*p,I r,I*sd){I i,o=0,b=0,s=0,w=0,g=0,e=0,c=0,cf=1,m=0;K q=0,a=ktn(11,0),v=ktn(0,0);
  for(i=b=0;i<r;++i){switch(p[i]){
  case'\n':if(!e)e=i;if(!q){q=kpn(p+w,g-w);if('\r'==(cf=p[i-1]))cf=p[i-2];}else if(!c){w=!!strchr("kK1",cf);if(!o)sc(d,0,sd);else if(w){if('g'==o)cwrite(f,OK("200","keep-alive")BLANK);else cwrite(f,OK("204","keep-alive")END204);}else{if('g'==o)cwrite(f,OK("200","close")BLANK);else cwrite(f,OK("204","close")END204);close(f);}a=k(o?-d:d,"dash",knk(2,q,xD(a,v),0),0,0);b=i+1;if(!o){if(!a){poop(f);R 0;}if(10!=a->t){r0(a);poop(f);R 0;}writer(f,kC(a),a->n);r0(a);if(!w)close(f);}if(b==r)R 1;q=0;o=0;a=ktn(11,0),v=ktn(0,0);}else{if((c-m)==10&& !strncasecmp(p+m,"connection",c-m))cf=p[s];js(&a,sn(p+m,c-m));jk(&v,kpn(p+s,e-s));}w=e=g=s=c=0;m=i+1;break;
  case' ':case'\t':case'\r':if(w&&!g)g=i;if(s==(e=i))++s;break;
  case':':if(!c)s=1+(c=i);break;
  case '/':if(!w)w=i+1;case '?':case '&':if(r>=(i+4)&&p[i+1]=='f'&&p[i+2]=='=')o=p[i+3];default: e=0;break;}}if(a)r0(a),r0(v);if(q)r0(q);R b;}
Thanks, I learned about something I absolutely hate.


Likely targeting c89, which doesn't have the fixed-size ints (nor size_t, as the sibling suggests).


My recollection was that size_t and ptrdiff_t were present in c89. size_t was the type yielded by sizeof. This draft appears to corroborate my recollection:

http://port70.net/~nsz/c/c89/c89-draft.html#3.3.3.4


In this case it also makes most sense to use size_t, right?


Depends.

If you use size_t all the time, you may forget or have someone else forget that another system isn’t the same.

If you always use uint8_t or int64_t etc there is no ambiguity. If I intended this to be an 32bit var, it will be regardless if who is compiling it.


But this is an allocation function, where the amount of data to be allocated is specified in bytes. That must surely use size_t. Imagine the case where 128 bit systems become popular and you want to use this function to allocate 2^70 bytes of memory. Using uint64_t here would be invalid in that case.


If you’re going to allocate like that you could use 8s and get any multiple you like, no?

I’ll give you that there are times for performance you want the native system type. But I would still prefer to use uint32_t and specify this was optimized for a 32bit system.




Consider applying for YC's Summer 2026 batch! Applications are open till May 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: