Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Lazy dope vectors by Henry Kroll III www.thenerdshow.com
//clang 3.7.0 #include <stdio.h> //simple c89 dope vector Copyright(C) 2016 Henry Kroll III www.thenerdshow.com typedef float data_t; typedef struct { char *name; size_t length; data_t *data; } ds; //print function void print_array (ds *dv) { printf("%s->data = (data_t[%li]){", dv->name, dv->length); for(int i=0;i<dv->length;i++) { printf("%3.1f, ", dv->data[i]); } puts("}"); } //define NEW dope vector, get size, reserve memory, and init (do not free()) #define NEW(id, ...) \ ds *id=&(ds){#id, sizeof(data_t[]){__VA_ARGS__}/sizeof (data_t), \ (data_t[]){__VA_ARGS__}} //main int main (void) { //easily create new dope vector pointer and memory without malloc NEW(dv, 0,1,2,3,4,5); //no more using &reference operator to pass it to functions print_array (dv); //access data with arrow-> not dot printf ("dv->data[2]=%3.1f\n", dv->data[2]); return 0; }
run
|
edit
|
history
|
help
0
Triangulo Lateral Izquierdo
lab7OOP 0.1
ternary test c89
Ecuación de segundo grado
Vzdalenost makro
Vectores: buscar valor en array
Herout (67) - 4
C99 doesn't allow initializers in if-conditions, so this does not compile.
Pointer_Indirectare_N
Bucles: terna pitagórica