All Questions
60 questions
0
votes
1
answer
242
views
Is it true that variable type before name makes compiler work easier? [closed]
I have seen information that at least one of reasons why type placed before variable name is that it allows compiler easier evaluate size and type of variable. If so then how (what way) it eases this ...
0
votes
1
answer
839
views
Custom #pragma directives
I'm creating a language parser on a microprocessor in C++. For the tables of keywords and commands, rather than maintaining a single curated file (alphabetically sorted, etc), I'd prefer to declare ...
-1
votes
1
answer
235
views
Better way to represent grammar symbols in C
I'm trying to build a simple compiler for a subset of the C language in C. To achieve this, I needed to figure out a way to represent the grammar symbols. Basically, each symbol can either be a "...
0
votes
2
answers
2k
views
Why are some languages called platform dependent if I can always share the source code?
I was reading about erlang when I read that it is platform-independent, using BEAM as the VM, now I understand that a VM compiles the byte code to machine code and this makes that language machine-...
23
votes
8
answers
6k
views
Detect manual changes to an autogenerated C header [closed]
I have a C header that is generated from a CSV file and a Python script. The C header mainly contains a list of #define constants.
I want to be able to detect manual changes to this header during ...
1
vote
1
answer
195
views
Switching out implementation source files in C project
For simplicity, let's say I have the following C project structure:
src/
utils/
logger.c
logger.h
main.c
secondary_component.c
main.c starts with:
#include "utils/logger.h"
I would ...
7
votes
2
answers
9k
views
What is the difference between a static library and an archive library?
In the comments of a recent answer, I equated a static library with an archive of compiled object files.
The response was that they are not the same, so what is the difference?
To clarify - gcc ...
2
votes
3
answers
4k
views
How does a compiler work when it's not directly compiling to machine code
I know the compilation process goes with this flow:
source -> parse -> AST -> intermediate code -> assembly -> machine code
and in the case of Java you will have bytecode which is ...
3
votes
4
answers
3k
views
GCC or Clang to output bytecode for a VM?
Long story short, I wanted to use C as a scripting language and in a portable manner so I created a register-based, JITless VM to accomplish this.
I've formalized the VM's ISA, script file format, ...
0
votes
2
answers
4k
views
Understanding Context Free Grammar using a simple C code
I'm trying to understand the difference between terminal and non-terminal values in a real language. I wasn't able to find enough examples on real language CFGs on the internet, most examples are ...
-7
votes
1
answer
416
views
Why does the C compiler use memory for simple arithmetic operations
Assume the following C code:
#include <stdio.h>
int main()
{
int a = 5;
int b = 15;
return a + b;
}
Compiling it using gcc creates an assembly code which includes the following:
...
4
votes
4
answers
5k
views
Rely on compiler to remove unused code or #ifdef out?
I am working on a USB stack in C. This stack will be open source and used in various different projects.
Various configuration options are available, which enable or disable large chunks of code and ...
6
votes
1
answer
7k
views
Is there any use case for using 'L' letter after a number literal in C?
I know that in C code using L after a number tells the compiler that the respective number is L.
However I do not see any practical use for this. Do modern compilers still have a use for this ...
11
votes
2
answers
19k
views
Why C allows multiple global declarations of the same variable but NOT multiple local declarations?
I noticed that if I declare a global variable multiple times the compiler does not even output a warning.
However if I declare a local variable in a function multiple times, for example, the gcc ...
0
votes
4
answers
593
views
Regarding a variable in C, is an assignment always equivalent to a definition of that variable? [closed]
Is there a difference between defining a variable in C and assigning a value to a variable in C?
I know that declaring a variable simply means telling the name and its type like int a.
On the other ...