C is a general-purpose computer programming language used for operating systems, games and other high performance work.
0
votes
1answer
83 views
Kernel facilities needed for C++
I'm working on a kernel for a proprietary embeded system. I've had no issues but I'd like to expand its capabilities directly. I made it run C. I did so pretty much by giving my kernel a stack.
My ...
-5
votes
0answers
62 views
How does decimal come into play when asked for converting decimal into ASCII? [on hold]
I am trying to find consistency here. When asked for "write a function that converts decimal to ASCII", how should I perceive the decimals?
ASCII :- Are from 0-127. eg: 65 is 'A'
So When I get ...
1
vote
1answer
81 views
Best way to use a C++ style api from a C style file compiled in C++
I am working a in a Telecom company. We have some code generation tools that generate C style files based on a MIB definition. We compile them with C++ though. It boils down to the fact that these ...
1
vote
1answer
121 views
In C, are large 'pointer chains' bad for performance or code cleanliness?
The following for example:
i = readString(&packet->data.play_server.updatesign.line1, pbuf, ps);
It has a large amount of nested structs/unions. Is this generally frowned upon in code ...
-2
votes
0answers
75 views
Languages which compile to C [closed]
I need to do some embedded development in ANSI C. I really don't want to work in C as it's missing a lot of higher level features (mainly closures, I just can't live without closures).
What options ...
2
votes
1answer
78 views
What method for storing a text file in memory (c not c++) would allow me to open any format(UTF-8, Binary, etc) and a file of any size?
My first thought here is to use a dynamic array, but I am looking for something better.
Currently I have the text files open into "chunks". Every word or group of spaces makes up a "chunk". Then I ...
0
votes
1answer
68 views
freed unallocated memore in C: how to fix it? [closed]
I was trying to write a one dimensional cellular automaton that updates n-generations for m numbers, where n and m are gotten from the user in main. however, since we were learning dynamic memory ...
2
votes
1answer
78 views
How would I organize a C project that uses libraries?
First off, I'm relatively new to C - I know the language somewhat, but never looked too much into the whole build process.
From what I'm seeing, if I want to use a third party library and have it in ...
7
votes
2answers
188 views
Why isn't there generic batching syscall in Linux/BSD?
Background:
System call overhead is much larger than function call overhead (estimates range from 20-100x) mostly due to context switching from user space to kernel space and back. It is common to ...
0
votes
4answers
328 views
Are there reasons to assign NULL instead of 0 to non-pointer variables?
Assigning variables with values during definition is a good practice.
A common practice is to assign variables with 0 and pointers with NULL.
int p = NULL; // instead of int p = 0;
int *ptr ...
0
votes
1answer
101 views
Using syscalls to read files - is this bad?
I have some (presumably stable) legacy C code that uses POSIX system calls to read binary files. It's nothing more than creat(), read(), and write(). The program doesn't sit close to the metal at all ...
-1
votes
3answers
178 views
How are expressions evaluated in Turbo C++?
I was reading about casts in c++ and got confused about how are the expressions actually evaluated. Consider the following code in which var is of type int and after the expression var = (var*10)/10 ...
4
votes
1answer
90 views
Why would you want different identifiers for a typedef and its associated struct tag?
Ignoring (with difficulty) Occam's Razor which would seem to put this quickly to rest, what advantage would this have:
typedef struct s_header {
struct s_header *next;
//...
} Header;
over ...
3
votes
1answer
311 views
What do banks actually use as a data type for money? [closed]
I'm aware of a few good options:
Big integers (e.g., int64_t, mpz_t, any bignum lib) to represent cents or 10-n cents—say, an integer represents 1/100 of a penny ($1.05 == 10500). This is called a ...
0
votes
1answer
86 views
Consistency of Undefined behavior
If there's a bug that triggers undefined behavior in a piece of code, is the undefined behavior consistent each time running it? and changes each time compiling it?
For example if you had some C code ...
2
votes
5answers
619 views
Why do so many languages restrict string literals to a single source line? [closed]
In, for example, the Bash scripting language, the following creates a string called $VAR which begins at the first " quote and continues until the next unescaped " quote.
$VAR="
hello
world!
...
-1
votes
1answer
49 views
Finding register parameters for system calls
By consulting various scattered tutorials and books, I've been able to learn that the 64-bit Linux "exit" system call is 60, and the status value is moved to edi. Similarly, "write" has call number 1, ...
18
votes
1answer
422 views
What is the origin of the C Preprocessor?
The C preprocessor is attached to C, but it has a completely different syntax from the main language:
syntactically significant whitespace (end of line terminates a statement, gap after the macro ...
4
votes
3answers
93 views
Unit Testing Module-Internal Functions
I'm writing a simple whitebox unit testing suite for a project I'm working on in C. The project is broken into modules (each has a .c file with an associated .h file), and all modules are compiled ...
-1
votes
1answer
51 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 ...
27
votes
13answers
2k views
Help in understanding computer science, programming and abstraction [duplicate]
Until now, I always believed that you should learn programming languages that make you do low-level stuff (e.g. C) to understand what's really happening under the hood and how the computer really ...
12
votes
5answers
1k views
Is it bad to write object oriented C? [closed]
I always seem to write code in C that is mostly object oriented, so say I had a source file or something I would create a struct then pass the pointer to this struct to functions (methods) owned by ...
-2
votes
1answer
172 views
Could ANSI C standardized linkage syntax from early C wrong? [closed]
Recently I came up to something illogical, reading the latest ANSI C paper. It was talking about linkage but it never mentioned a way to declare internal identifiers inside block-scope (or at least in ...
0
votes
2answers
153 views
Efficient Repeating Alarm Clock in Low Level Language like C
I was thinking about it and I was curious as to how one would code an efficient repeating alarm clock in C? Would you set an alarm time and then offset the time with the ms time equivalent of a day ...
29
votes
5answers
5k views
If a number is too big does it spill over to the next memory location?
I've been reviewing C programming and there are just a couple things bothering me.
Let's take this code for example:
int myArray[5] = {1, 2, 2147483648, 4, 5};
int* ptr = myArray;
int i;
for(i=0; ...
7
votes
1answer
103 views
Unit Testing: Assembler code and different architectures
I am currently unit testing some C code and I am faced with a problem:
Within the code there are called functions that contain inline assembler code for the SPARC 8 architecture.
Since I am doing ...
9
votes
3answers
358 views
How useful is C's “true” sizing of variables?
One thing that always intuitively struck me as a positive feature of C (well, actually of its implementations like gcc, clang, ...) is the fact that it does not store any hidden information next to ...
-2
votes
1answer
99 views
Problem on recursion
void function(int x){
if(x<=0)
return;
function(x--);
}
This is a recursion function which is called with the value of x = 20.
The Recursive call will take place in this way
...
1
vote
2answers
126 views
Declaration confusion in pointers [closed]
I was just confused about the following declaration in C:
char **p[5]
I understand the char *p[] as an array of character pointers, but this one is puzzling me. Based on the precedence of [] over ...
10
votes
4answers
246 views
Is there a standard way or standard alternative to packing a struct in c?
When programming in C I have found it invaluable to pack structs using GCCs __attribute__((__packed__)) attribute so I can easily convert a structured chunk of volatile memory to an array of bytes to ...
7
votes
5answers
345 views
What does it mean to declare a volatile variable?
Many low level programs use the volatile keyword for types for memory mapping and such, however I'm sort of confused as to what it REALLY does in the background. In other words, what does it mean ...
3
votes
1answer
106 views
How to communicate between cooperative tasks “first me, then you”?
I am in the final stages of development of a simple embedded system. The device performs PID coefficient estimation and then instantiates a PID controller with the estimated coefficients.
The ...
5
votes
3answers
136 views
How to create “constructors” for structures in C
The problem
I have this structure that I want to create a "constructor" for it.
struct example {
int x, y, z; /* various members */
struct another *another; /* pointer to another structure ...
33
votes
9answers
3k views
Doesn't “always initialize variables” lead to important bugs being hidden?
The C++ Core Guidelines have the rule ES.20: Always initialize an object.
Avoid used-before-set errors and their associated undefined behavior. Avoid problems with comprehension of complex ...
10
votes
3answers
447 views
Is it bad to refer to access array elements via pointer arithmetic instead of the [] operator?
I've just started learning to program in C, and to improve my understanding of pointers and arrays, I tried to refer to the elements of an array without creating any pointer at all:
for(k1 = 0; k1 ...
20
votes
2answers
2k views
Are header-only libraries more efficient?
Assumptions
One of the advantages of header-only libraries for C++ is that they do not need to be compiled separately.
In C and C++ inline makes sense only if the function is defined in a header ...
25
votes
10answers
5k views
Isn't the use of pointer variables a memory overhead?
In languages like C and C++, while using pointers to variables we need one more memory location to store that address. So isn't this a memory overhead? How is this compensated? Are pointers used in ...
2
votes
2answers
120 views
Difference in endianness between operating systems [closed]
There is an assembler that I am writing that is located within the file asm.c located in this repository. It uses the instruction set located in the specs file to produce an output binary. (The ...
1
vote
1answer
40 views
Efficiently determining many-to-many subset relation
I'm doing market basket analysis. I have a set of transactions. Every transaction is a set of items that were bought. I then have a set of itemsets (i.e. a set of items) that I want to determine the ...
-1
votes
1answer
69 views
What is the hash value of each member of the group? Before modding?
This isn't an actual code related question but it relates to C. We are given:
Amy's club has grown and now includes the following members: Abel, Abigail, Abraham, Ada, Adam, Adrian, Adrienne, ...
1
vote
2answers
52 views
One C codebase as an standalone application as well as Fast-CGI and Apache module
I'm familiar with C, but haven't written any medium or large application in it. I have a requirement to built an application that can be run as a standalone console application as well as Fast-CGI and ...
-2
votes
1answer
366 views
Bresenham Vs Midpoint Circle drawing algorithm
Can somebody explain the difference between Bresenham and Midpoint Circle drawing algorithms? All I am able to understand is that in both algorithms we compute coordinates of an octant instead of ...
5
votes
1answer
122 views
Strategies to increasing the maintainability of assertions in code [closed]
Background
I am writing a compiler for a custom language for a school project and it is going really well for me.
If I where to start all over from scratch I would have done many software ...
3
votes
1answer
194 views
Are include guards necessary if headers only contain declarations?
Consider the following assumptions about C programming (some of which go too far, I confess):
Putting any variable definitions in a header file is incorrect, because each translation unit creates ...
-2
votes
1answer
145 views
How did the gets function ever make into the standard? [closed]
We all know the dangers of gets.
It is also on the way out in C11.
That makes me wonder: how did it ever get into the standard to begin with? Weren't the problems with it obvious at the time of ...
-2
votes
1answer
160 views
Why '-5<(unsigned)5' is false? [duplicate]
In c programming why I am getting 0 zero for this? Why -5<(unsigned)5 is false?
main(){
printf("%d",-5<(unsigned)5);
getch();
}
0
votes
2answers
368 views
Write C line by line
Is there any conceptual limitation that would make impossible to create a C program line by line as in 'Mathematica notebooks'[1]?
[1] One key aspect of Mathematica is that you can create your code ...
-1
votes
1answer
177 views
Is C programming language low level or high level? [duplicate]
What do you think, is C programming language low or high level?
There are some information, in one is said that C is low level, and another C is high level? When I read book of Dennis Ritchie and ...
52
votes
7answers
4k views
Should one check for every little error in C? [duplicate]
As a good programmer one should write robust codes that will handle every single outcome of his program. However, almost all functions from the C library will return 0 or -1 or NULL when there's an ...
0
votes
1answer
52 views
Overwriting a C system after exec? [closed]
So I used wrap to override the malloc call in my program, I didn't think that if I exec'd another it would work, and it didn't. I figure this is because it wasn't linked with my program. How could I ...