I stopped even scanning it when the "solution" for the "common beginner mistake" of array overflow is not sizeof() but
``` { const int len = 5; int a[len] = {1,3,5,7,9}; ```
I stopped even scanning it when the "solution" for the "common beginner mistake" of array overflow is not sizeof() but
``` { const int len = 5; int a[len] = {1,3,5,7,9}; ```
> if you want to modify a value you either have to use a pointer to the memory address:
void increment_a(int *a)
{
*a++;
}
int solve(void)
{
int a = 5;
increment_a(&a);
} int increment(a)
{
return a+1;
}
void somefunc()
{
int b = 5;
b = increment(b);
printf("b now %d\n", b);
}that's latest GCC, at -O3
But yes, sadly I think it's still generally advisable to avoid returning large structs by value.
Note that this has nothing to do with RVO; as I understand it, RVO is about eliding copy constructors, not actual memory copies, and c has no copy constructors and so gets 'RVO' in all cases.
For the use cases that are too expensive to use functions, macros can be used instead.
However that is only if C++ cannot be used at all, otherwise don't bother.
T get_t(int how, char **error);
int get_val(T *v);
One could rewrite these as struct get_t_res {T; char *};
struct get_t_res get_t(int);
struct get_val_res {int; T};
struct get_val_res get_val();
But what do you think of it? *a++
doesn’t increment the value pointed to by `a`, it increments `a` itself. The value remains intact.Noob mistake
if (f != 1.1)
puts("Do not compare a float to an integer value\n");
if (d == 1.1)
puts("But that's okay for a double\n");
In the back of my mind there's the fear that all of this was actually mean seriously... prog.c: In function ‘somefunction3’:
prog.c:8:2: error: variable-sized object may not be initialized
int a[len] = {1,3,5,7,9};
^~~