Skip to main content

All Questions

Tagged with
0 votes
1 answer
186 views

Elegant way in C to store many parameters with default value and current value in embedded flash

I'm programming an embedded system that has a number of user configurable parameters, which are stored in flash memory. I have to store a default value for each parameter as well as the user settings. ...
jusaca's user avatar
  • 175
26 votes
6 answers
24k views

How can Rust be "safer" and "faster" than C++ at the same time?

I have been told that Rust is both safer and faster than C++. If that is true, how can that be even possible? I mean, a safer language means that more code is written inside the compiler, right? More ...
euraad's user avatar
  • 393
5 votes
2 answers
3k views

Why does C not support direct array assignment?

In C you cannot assign arrays directly. int array[4] = {1, 2, 3, 4}; int array_prime[4] = array; // Error At first I thought this might because the C facilities were supposed to be implementable with ...
CPlus's user avatar
  • 1,199
-2 votes
1 answer
120 views

Are jagged arrays lvalue or not?

When I was study lvalue i see that C expression can be lvalue if a subscript ([]) expression that does not evaluate to an array. (from https://docs.microsoft.com/en-us/cpp/c-language/l-value-and-r-...
Ulaş Sezgin's user avatar
2 votes
2 answers
706 views

sizeof(a)/sizeof(a[0]) vs sizeof(a)/sizeof(t) where t is type in C from K.N.King

I'm trying to understand why sizeof(a)/sizeof(t) is inferior for getting the length of an array to sizeof(a)/sizeof(a[0]) if just as it's possible to have different types, my elements could also be of ...
Farah Kamal's user avatar
1 vote
3 answers
2k views

Does the gcc optimize out local arrays the same way it would optimize out a local variable?

If I write this code in a function: void func(void) { int x = 0; int y = 3724832+x; } It would (probably) optimize the variable y out because it isn't being used. Even if I'm wrong about this ...
user avatar
2 votes
3 answers
3k views

Return array pointers vs. populating an array inserted as a parameter?

Which is better? I noticed the latter is used in a lot of C code. People will typically malloc an array, and then pass that as a parameter to a function, which will then populate it. Whereas in Java, ...
user3724404's user avatar
2 votes
1 answer
201 views

Handling out of bounds requests in embedded C library

We're currently building a library in C that configures itself from tables in EEPROM. This leaves the possibility however that some caller requests a field that is out of bounds, and the question ...
bemk's user avatar
  • 39
1 vote
2 answers
569 views

How do I best store a value with multiple keys?

I need to store two 32-bit numbers in a way that is quickly accessible and as storage space efficient as possible. My keys are a combination of the following two values: port: 0 - 29 vlan: 1 - 4095 ...
stdcerr's user avatar
  • 139
0 votes
4 answers
2k views

How does C know the bounds of a multi-dimensional array?

Coming from Python, if C does not have array bounds, how does it know where a[1] starts? int a[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}; b = a[1][1];
Philip Ridout's user avatar
-1 votes
1 answer
5k views

(Multidimensional array in C) How to make my output in a vertical position rather than in horizontal when the size of the array is n[3][4] [closed]

I would like to have some help. I must find a way that the output must be: A B C 90 60 80 50 100 70 100 20 100 10 50 75 Because the previous output is: A 90 50 100 10 B 60 100 ...
Carbine Alejandro's user avatar
15 votes
1 answer
833 views

Why prefer sizeof(element) over sizeof(TYPE) for calculating the number of elements in an array?

I'm reading "King K.N's C programming" and found the following statement: We discussed using the expression sizeof(a)/sizeof(a[0]) to calculate the number of elements in an array. The expression ...
Higgs's user avatar
  • 169
-3 votes
1 answer
86 views

How can this allocation of bi-dimensional arrays work? [closed]

I was seeing this post on StackOverflow and saw a new way (at least for me) to define a two dimensional array of 5x5, it works well, but I feel I don't understand what is going on in the background. ...
OiciTrap's user avatar
  • 729
1 vote
3 answers
665 views

Question about multidimensional arrays

I was wondering something about the multidimensional arrays and then I got a doubt about a concept, specifically about their representation on memory. For example, an array can be defined as follows. ...
OiciTrap's user avatar
  • 729
14 votes
6 answers
9k views

Why can't C arrays have 0 length?

The C11 standard says the arrays, both sized and variable length "shall have a value greater than zero." What is the justification for not allowing a length of 0? Especially for variable length ...
Kevin Cox's user avatar
  • 251

15 30 50 per page