Programming questions are off-topic here. Do not ask questions about how to write code in C. However, conceptual questions about computer science are more appropriate. See our help center for the scope of this site.
Questions tagged [c]
108 questions
67
votes
14 answers
Is C actually Turing-complete?
I was trying to explain to someone that C is Turing-complete, and realized that I don't actually know if it is, indeed, technically Turing-complete. (C as in the abstract semantics, not as in an actual implementation.)
The "obvious" answer…
TLW
- 1,500
- 1
- 10
- 16
31
votes
2 answers
Why is C's void type not analogous to the empty/bottom type?
Wikipedia as well as other sources that I have found list C's void type as a unit type as opposed to an empty type. I find this confusing as it seems to me that void better fits the definition of an empty/bottom type.
No values inhabit void, as far…
Meta
- 413
- 4
- 6
14
votes
7 answers
Why do negative array indices make sense?
I have came across a weird experience in C programming. Consider this code:
int main(){
int array1[6] = {0, 1, 2, 3, 4, 5};
int array2[6] = {6, 7, 8, 9, 10, 11};
printf("%d\n", array1[-1]);
return 0;
}
When I compile and run this, I don't…
Mohammed Fawzan
- 283
- 1
- 4
- 8
11
votes
10 answers
In C, why limit || and && to evaluate to booleans?
In some languages, e.g. Ruby, an expression like:
val = call_fn() || DEFAULT_VAL;
will set val to the results of call_fn() if it is truthy (non-zero, non-NULL, etc), or to DEFAULT_VAL otherwise. This can be really useful.
In C, the result of the…
fearless_fool
- 445
- 5
- 12
9
votes
7 answers
Checking equality of integers: O(1) in C but O(log n) in Python 3?
Consider these equivalent functions in C and Python 3. Most devs would immediately claim both are $O(1)$.
def is_equal(a: int, b: int) -> bool:
return a == b
int is_equal(int a, int b) {
return a == b;
}
But consider what is happening under…
jtschoonhoven
- 297
- 1
- 3
- 9
8
votes
4 answers
How does the linker know where to look for a function implementation in C++?
I am currently learning about how the compilation and linking works in C++. I think I kinda get how the compiler works, and that for a file to fully compile you don't need to have function implementations, but only declarations. It is the linker's…
artas2357
- 183
- 1
- 6
7
votes
1 answer
Is the Syntax of C Language completely defined by CFGs?
I think the Question is self sufficient. Is the syntax of C Language completely defined through Context Free Grammars or do we have Language Constructs which may require non-Context Free definitions in the course of parsing?
An example of non CFL…
Madeyedexter
- 171
- 4
6
votes
1 answer
How are extremely large integers stored and implemented in programming languages?
We have data types like int and long etc. which can store just a few bytes of integers.
But when we are implementing cryptographic algorithms like RSA or Elliptic Curves, we know that the key values are usually 1024 bits long.
How is this…
Yuv
- 139
- 7
5
votes
0 answers
Dennis Ritchie citation for "the C declarator syntax is an experiment that failed"?
I've often heard that the C declarator syntax described as "an experiment that failed." I've seen claims that this sentiment is also shared by its creator Dennis Ritchie. Does anybody have an actual citation for this?
I'm doing a related project and…
Paul J. Lucas
- 159
- 2
5
votes
3 answers
automatic memory allocation
Global variables are given fixed addresses in main memory by the C compiler, called static memory allocation. Function local variables are created on the stack, this is called automatic memory allocation.
Why is it done this way?
DanielJackson1
- 63
- 3
4
votes
1 answer
Sorting Algorithm with constraints
I am looking for a sorting algorithm to help me in my work. My objective is the following: after receiving an input of this kind:
5 4
1 2
2 3
3 4
4 5
The first line tells me how many ids I have, and the second number tells me how many connections.…
Daxter
- 41
- 1
3
votes
3 answers
How to enhance my skills as a programmer
I want to learn Cryptography and so I am interested to master C-programming.
I know the basic concepts of C-programming like how to use an array,pointers etc.
I want to develop myself so that I can find the different loopholes in the security of…
user44840
3
votes
1 answer
Hash multiple integers directly using FNV-1a
An alternative version of FNV-1a hash spread on the internet, which operates directly on integers instead of bytes. The offset basis and prime are the same used in the original version, which operates on bytes.
With this version, is the statistical…
plasmacel
- 207
- 2
- 11
3
votes
0 answers
What algorithm can be used to implement code folding for the C programming language?
I'm working on a simple editor for the C programming language (without using an AST), and I need to implement a code folding feature.
When the user opens a file, an initial parse is performed, and all {} code blocks are easily detected. I store…
SilverCube
- 131
- 3
3
votes
4 answers
Are float pseudo-random number generators always implemented using integer generators underneath
In C it's well known to use simple routine for turning integer rng into float rng. Something like that
float frand( float min, float max ) {
float scale = rand()/(float)RAND_MAX; // [0, 1.0]
return min + scale * (max - min); // [min,…
simd
- 131
- 2