licence and stuff plus minor changes
This commit is contained in:
parent
53e4cb652f
commit
fe07cf2106
@ -10,9 +10,9 @@ int main() {
|
|||||||
size_t n = 0;
|
size_t n = 0;
|
||||||
printf("Number of elements to sum: ");
|
printf("Number of elements to sum: ");
|
||||||
scanf(" %zu", &n);
|
scanf(" %zu", &n);
|
||||||
/* Create a 64 bit array of 'n' elements */
|
|
||||||
|
/* Create a 64 bit array of 'n' elements named 'data' */
|
||||||
creat(Array_uint64, data, &n);
|
creat(Array_uint64, data, &n);
|
||||||
// printf("vektor.count:%d\n", data.count);
|
|
||||||
|
|
||||||
for(int i = 0; i < data.count; ++i) {
|
for(int i = 0; i < data.count; ++i) {
|
||||||
scanf(" %zu", &n);
|
scanf(" %zu", &n);
|
||||||
@ -22,5 +22,6 @@ int main() {
|
|||||||
printf("Sum: %zu\n", n);
|
printf("Sum: %zu\n", n);
|
||||||
|
|
||||||
// RAII releases array here automagicaly!
|
// RAII releases array here automagicaly!
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -6,10 +6,10 @@ struct Vektor {
|
|||||||
int count;
|
int count;
|
||||||
int *v;
|
int *v;
|
||||||
}; handle(Vektor) {
|
}; handle(Vektor) {
|
||||||
if(state == HANDLE_CREAT) {
|
if(HANDLE_CREAT == state) {
|
||||||
self->count = *(int*) data;
|
self->count = *(int*) data;
|
||||||
self->v = (int*) calloc(self->count, sizeof(int));
|
self->v = (int*) calloc(self->count, sizeof(int));
|
||||||
} else if (state == HANDLE_DESTR){
|
} else if (HANDLE_DESTR == state){
|
||||||
if(self->v) free(self->v);
|
if(self->v) free(self->v);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -19,7 +19,7 @@ int main() {
|
|||||||
printf("Number of elements to sum: ");
|
printf("Number of elements to sum: ");
|
||||||
scanf(" %d", &n);
|
scanf(" %d", &n);
|
||||||
creat(Vektor, data, &n);
|
creat(Vektor, data, &n);
|
||||||
// printf("vektor.count:%d\n", data.count);
|
// printf("data.count:%d\n", data.count);
|
||||||
|
|
||||||
for(int i = 0; i < data.count; ++i) {
|
for(int i = 0; i < data.count; ++i) {
|
||||||
scanf(" %d", &n);
|
scanf(" %d", &n);
|
||||||
|
11
array_test.c
11
array_test.c
@ -14,6 +14,14 @@ Vektor create_Vektor(int count) {
|
|||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int sum_Vektor(Vektor *self) {
|
||||||
|
int s = 0;
|
||||||
|
for(int i = 0; i < self->count; ++i) {
|
||||||
|
s += self->v[i];
|
||||||
|
}
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
void delete_Vektor(Vektor *self) {
|
void delete_Vektor(Vektor *self) {
|
||||||
if(self->v) free(self->v);
|
if(self->v) free(self->v);
|
||||||
}
|
}
|
||||||
@ -29,7 +37,8 @@ int main() {
|
|||||||
scanf(" %d", &n);
|
scanf(" %d", &n);
|
||||||
data.v[i] = n;
|
data.v[i] = n;
|
||||||
}
|
}
|
||||||
n = 0; for(int i = 0; i < data.count; ++i) n += data.v[i];
|
// n = 0; for(int i = 0; i < data.count; ++i) n += data.v[i];
|
||||||
|
n = sum_Vektor(&data);
|
||||||
printf("Sum: %d\n", n);
|
printf("Sum: %d\n", n);
|
||||||
|
|
||||||
// Need to not forget this
|
// Need to not forget this
|
||||||
|
@ -6,8 +6,8 @@ void __attribute__((destructor)) calledLast();
|
|||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
printf("\nI am in main");
|
printf("\nI am in main");
|
||||||
// return 0;
|
return 0;
|
||||||
exit(0); // Even called on this!!!
|
// exit(0); // Even called on this!!!
|
||||||
}
|
}
|
||||||
|
|
||||||
void calledFirst() {
|
void calledFirst() {
|
||||||
|
1
handle.h
1
handle.h
@ -1,6 +1,7 @@
|
|||||||
#ifndef MAG_HANDLE_H
|
#ifndef MAG_HANDLE_H
|
||||||
#define MAG_HANDLE_H
|
#define MAG_HANDLE_H
|
||||||
/* Simple single-header library that makes you have RAII in gcc (also works in C++ compilers) */
|
/* Simple single-header library that makes you have RAII in gcc (also works in C++ compilers) */
|
||||||
|
/* Licence: CC-BY */
|
||||||
|
|
||||||
/** Tells your constructor/destructor handler function about the state */
|
/** Tells your constructor/destructor handler function about the state */
|
||||||
enum HANDLE_STATE {
|
enum HANDLE_STATE {
|
||||||
|
@ -8,6 +8,7 @@ struct Meaning {
|
|||||||
|
|
||||||
handle(Meaning) {
|
handle(Meaning) {
|
||||||
if(state == HANDLE_CREAT) {
|
if(state == HANDLE_CREAT) {
|
||||||
|
// Constructor
|
||||||
self->a = *(int*) data;
|
self->a = *(int*) data;
|
||||||
self->b = 2;
|
self->b = 2;
|
||||||
} else {
|
} else {
|
||||||
|
19
innerf.c
19
innerf.c
@ -1,18 +1,27 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
int a = 0;
|
auto int a = 0;
|
||||||
int b = 40;
|
int b = 20;
|
||||||
int c = 2;
|
int c = 1;
|
||||||
|
int d = 0;
|
||||||
|
|
||||||
// See: https://gcc.gnu.org/onlinedocs/gcc-4.3.0/gcc/Nested-Functions.html
|
// See: https://gcc.gnu.org/onlinedocs/gcc-4.3.0/gcc/Nested-Functions.html
|
||||||
inline void lf(register int* r) {
|
inline auto void lf(register int *r) {
|
||||||
a += *r;
|
a += *r;
|
||||||
|
int s = a + *r;
|
||||||
|
inline void deepfun() {
|
||||||
|
s *= 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
deepfun();
|
||||||
|
d += s;
|
||||||
}; // semicolon(;) not needeed!
|
}; // semicolon(;) not needeed!
|
||||||
|
|
||||||
/*
|
/*
|
||||||
// Same as above... but need auto storage class if you pre-declare
|
// Same as above... but need auto storage class if you pre-declare
|
||||||
inline auto void lf(register int* r);
|
inline auto void lf(register int* r);
|
||||||
|
// ...
|
||||||
inline void lf(register int* r) {
|
inline void lf(register int* r) {
|
||||||
a += *r;
|
a += *r;
|
||||||
}; // semicolon(;) not needeed!
|
}; // semicolon(;) not needeed!
|
||||||
@ -21,6 +30,6 @@ int main() {
|
|||||||
lf(&b);
|
lf(&b);
|
||||||
lf(&c);
|
lf(&c);
|
||||||
|
|
||||||
printf("%d\n", a);
|
printf("%d .. %d\n", a, d);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user