Run Code
|
API
|
Code Wall
|
Users
|
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
Please
log in
to post a comment.
Bucles: Triángulos Lateral Derecho
Teylor
Regiones A y B
VKI_Mihalyk_3_2
Triples bucles anidados
Vzdalenost makro
Bucles: Suma de n números tecleados por el usuario
pattern1
Recursividad: Hanoi
Vectores: Burbuja
Please log in to post a comment.