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

printf is too verbose and retarded of a name

Name: Anonymous 2021-03-09 11:00

Hey queers! Here is a proper replacement for printf called shit()

#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <stdarg.h>

void hidden_shit(uint64_t a0, ...) {
va_list ap;
uint64_t type = a0;
va_start(ap, a0);
type = va_arg(ap, uint64_t);
for (int i = 0; type; i++) {
if (type > 32) {
printf("%s", (char*)type);
type = va_arg(ap, uint64_t);
continue;
}
if (type == 1) {
printf("%lld", va_arg(ap, uint64_t));
} else if (type == 2) {
printf("%llx", va_arg(ap, uint64_t));
} else if (type == 3) {
printf("%f", va_arg(ap, double));
} else if (type == 4) {
printf("%p", (void*)va_arg(ap, uint64_t));
}
type = va_arg(ap, uint64_t);
}
printf("\n");
va_end(ap);
}

#define shit(...) \
do { \
uint64_t S=1, X=2, F=3, P=4; \
hidden_shit((uint64_t)0,__VA_ARGS__,(uint64_t)0);\
} while(0)


int main() {
int a = 123, b = 456, c = 666;
shit("hello world!");
shit("c=",S,c);
shit(S,a,",",F,456.0,",",X,b,",done");
char *verb = "go fuck", *object = "yourself", *adjective = "dumbfuck";
shit(verb," ",object,", ",adjective);
return 0;
}

Name: Anonymous 2021-03-12 20:26

>>18
Yet it works well in practice. Here is how I use mAlloc to read a ply file, while making manual memory management manageable:

PLYObject *read_header(file_t *in) {
auto hdr = new(PLYObject);
PLYTable *table = 0;
if (in.line.ne("ply")) return 0;
int coloff;
char *l;
for (;;) {
l = in.line;
if (l.begins("end_header")) {
break;
}
char *p = l;
while (*p && *p != ' ') p++;
*p = 0;
p++;
if (!table) { //header field?
if (l.eq("format")) {
hdr->format = p.dup;
} else if (l.eq("comment")) {
hdr->comment.push(p.dup);
} else if (l.eq("element")) {
goto element;
}
continue;
}

if (l.eq("element")) {
element:
coloff = 0;
if (table) {
table->row_size = coloff;
}
table = new(PLYTable);
hdr->tbls.push(table);
char *q = p;
while (*q && *q != ' ') q++;
*q = 0;
q++;
table->name = p.dup;
table->nrows = q.asS32;
} else if (l.eq("property")) {
PLYColumn col;
col.ctor;
auto grp = mCurGrp();
mBegin(0);
auto words = p.split(' ');
mBegin(grp); //allocate at the level above
if (words->elts[0].eq("list")) {
col.name = words->elts[3].dup;
auto t = ply_named_types.get(words->elts[1]);
if (!t) {
say("PLY: bad header type = ", words->elts[1]);
return 0;
}
col.size_type = *t;
t = ply_named_types.get(words->elts[2]);
if (!t) {
say("PLY: bad header type = ", words->elts[1]);
return 0;
}
col.type = *t;
col.off = coloff;
coloff += sizeof(void*); //list will be a pointer
} else {
col.name = words->elts[1].dup;
auto t = ply_named_types.get(words->elts[0]);
if (!t) {
say("PLY: bad header type = ", words->elts[0]);
return 0;
}
col.type = *t;
col.off = coloff;
coloff += col.type->size;
}
table->cols.push(col);
mEnd();
mEnd();
}
}
return hdr;
}

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