licence and stuff plus minor changes

This commit is contained in:
Richard Thier 2025-04-25 21:44:24 +02:00
parent 53e4cb652f
commit fe07cf2106
7 changed files with 34 additions and 13 deletions

View File

@ -10,9 +10,9 @@ int main() {
size_t n = 0;
printf("Number of elements to sum: ");
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);
// printf("vektor.count:%d\n", data.count);
for(int i = 0; i < data.count; ++i) {
scanf(" %zu", &n);
@ -22,5 +22,6 @@ int main() {
printf("Sum: %zu\n", n);
// RAII releases array here automagicaly!
return 0;
}

View File

@ -6,10 +6,10 @@ struct Vektor {
int count;
int *v;
}; handle(Vektor) {
if(state == HANDLE_CREAT) {
if(HANDLE_CREAT == state) {
self->count = *(int*) data;
self->v = (int*) calloc(self->count, sizeof(int));
} else if (state == HANDLE_DESTR){
} else if (HANDLE_DESTR == state){
if(self->v) free(self->v);
}
}
@ -19,7 +19,7 @@ int main() {
printf("Number of elements to sum: ");
scanf(" %d", &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) {
scanf(" %d", &n);

View File

@ -14,6 +14,14 @@ Vektor create_Vektor(int count) {
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) {
if(self->v) free(self->v);
}
@ -29,7 +37,8 @@ int main() {
scanf(" %d", &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);
// Need to not forget this

View File

@ -6,8 +6,8 @@ void __attribute__((destructor)) calledLast();
int main() {
printf("\nI am in main");
// return 0;
exit(0); // Even called on this!!!
return 0;
// exit(0); // Even called on this!!!
}
void calledFirst() {

View File

@ -1,6 +1,7 @@
#ifndef MAG_HANDLE_H
#define MAG_HANDLE_H
/* 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 */
enum HANDLE_STATE {

View File

@ -8,6 +8,7 @@ struct Meaning {
handle(Meaning) {
if(state == HANDLE_CREAT) {
// Constructor
self->a = *(int*) data;
self->b = 2;
} else {

View File

@ -1,18 +1,27 @@
#include <stdio.h>
int main() {
int a = 0;
int b = 40;
int c = 2;
auto int a = 0;
int b = 20;
int c = 1;
int d = 0;
// 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;
int s = a + *r;
inline void deepfun() {
s *= 2;
}
deepfun();
d += s;
}; // semicolon(;) not needeed!
/*
// Same as above... but need auto storage class if you pre-declare
inline auto void lf(register int* r);
// ...
inline void lf(register int* r) {
a += *r;
}; // semicolon(;) not needeed!
@ -21,6 +30,6 @@ int main() {
lf(&b);
lf(&c);
printf("%d\n", a);
printf("%d .. %d\n", a, d);
}