C is a general-purpose computer programming language used for operating systems, games and other high performance work.

learn more… | top users | synonyms

1
vote
1answer
161 views

Unit testing C code?

I learnt about the check testing framework today that seems good. This far I've scripted tests that uses valgrind so that the tests both display output from the tests and from valgrind. Is there a ...
2
votes
1answer
215 views

When to malloc and free?

Valgrind does not report a memory leak during my actual usage, only during my scripted test that I scripted with a shell script to test my own shell. I found that I didn't have to use malloc every ...
2
votes
0answers
104 views

What are the benefits of an input/output component design?

For the company I work at, all of our projects, including a new one started last year, are written in C89. We write for vxWorks (a real time embedded operation system). Our software runs multi-...
-1
votes
1answer
68 views

During fork system call which execute first parent or child

As i am executing a one pipe example pgm from libc.pdf,I noticed that the parent process first completed then only child process completed.From my knowledged about os the child process must complete ...
-1
votes
2answers
79 views

Run C program in debug mode (without debugger)

If I want my program to be able to run in debug mode, is it a good idea to make it accept a flag such as -D=DEBUG when I run the program? I currently have a DEBUG variable in a .h file but that I can'...
2
votes
2answers
110 views

algorithm for shell language interpreter to find if a char is between quotes

Assume we have a string s (a C char *) that is a program in a language L. I want to parse L and know the following from the specification The following characters must be quoted if they are to ...
-2
votes
1answer
163 views

For loop and recursion for a new shell in C [closed]

I code a new shell in C, that could be done in several ways: Flex/bison, finite state machine, abstract syntax tree or just a tokenizer in C. Now I've written a for-loop that changes the condition of ...
2
votes
1answer
173 views

Is it impossible to write proper, const correct callbacks in C?

In C, a non const object implicitly converts, without warning, to its const counterpart, so you can write a function, and call it as: void foo( const char *p ); char bar[] = "bar"; foo( bar ); ...
1
vote
1answer
154 views

Does having so many macros (#define) increase compilation time due to prolonged pre-processing?

In a very simplistic way, I understand: "Compilation" = "Pre-processing" + "Parsing" + "Linking" + "Executable" All the macros and other such pre-processing directives are taken care at the "Pre-...
4
votes
4answers
342 views

Coding style: Binary logic or multiple if()s?

Something that often comes up in code reviews is the structure of the code, particularly related to the use of control structures, where individuals can be fairly opinionated on what is "right" and ...
2
votes
3answers
138 views

Is there any low level way to get shifted or unshifted bits which results from bitwise operations?

I was playing with bitwise operations and a question about counting true bits of any positive integer value, so I solved the problem with bit shifting, so I just thought if there would be some way to ...
2
votes
4answers
295 views

Are static global variables as bad as global variables? How to avoid using them?

In general, I know that global variables are bad and should be avoided. Are static global variables equally bad? In all my projects, I have heavily relied on static global variables. From design ...
4
votes
1answer
87 views

Kernel operation

I'm trying to grasp the concept of an operating system at the moment (on Unix-like machines) The kernel is the process with PID 0. Of course the Kernel is not really "just another process" because a ...
9
votes
2answers
334 views

Why were variable length arrays made optional in C 2011?

When VLAs were introduced in C 1999, I thought it was a great innovation to the language. However, having learned it was made optional in C 2011, I am wondering what led to its change in status, and ...
1
vote
1answer
157 views

Memory usage of global versus local variables

I am a beginner in C coding. I'm writing a C code where a variable is required to be used by different functions. I want to ask whether to use a global variable and manipulate it through functions or ...
1
vote
1answer
72 views

Using GPLed headers in LGPLed library

For a specific device there exists a Linux kernel module. This module only initialized the device and provides control mechanisms to user land via ioctls and mmap. To use this the device properly one ...
19
votes
1answer
472 views

Where did “exit(-1)” come from?

I see in a lot of legacy software and bad tutorials on the Internet that recommend using exit(-1), return -1 or similar to represent "abnormal termination". The problem is, in POSIX at least, -1 has ...
0
votes
1answer
323 views

One font OCR for meme images

I'm coding an Optical Character Recognition specifically for the Internet meme images. This is a school project and it should be coded in C. I'm currently having trouble with the method/algorithms I ...
3
votes
2answers
125 views

How can I tell what standard my C is in?

Okies, totally newbie question here. I can read the code, mimic the code and understand the basics to be deadly. But, I never really took the time to understand what ANSI C really meant. I just look ...
2
votes
3answers
179 views

When does gcc not work on Windows [closed]

Everyone (who knows C) always tells me to be careful when using gcc to compile on Windows, yet they never actually tell me what the compatibility issues are. I'm left to believe that gcc is just 'not ...
3
votes
1answer
106 views

How do you manage your OpenCL source?

I am having a hard time deciding how I should manage my OpenCL source code so that my program can compile it at runtime. There seem to be two many strategies. You can create them in you C source as ...
3
votes
2answers
216 views

Why doesn't C have first class arrays? [duplicate]

I've got a question about the semantics of C and was wondering why the powers that be decided to make arrays different from every other type in the language. I understand that arrays and pointers are ...
0
votes
1answer
169 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 ...
2
votes
1answer
101 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
174 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
1answer
113 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 ...
2
votes
1answer
96 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 ...
8
votes
2answers
245 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
426 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
115 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
186 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
101 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
384 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 ...
1
vote
1answer
95 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 ...
1
vote
4answers
708 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
59 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, ...
20
votes
1answer
479 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
116 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
61 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 ...
30
votes
13answers
3k 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
182 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
228 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; i&...
7
votes
1answer
134 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
376 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 ...
-1
votes
1answer
107 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
130 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
381 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
408 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 ...