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

learn more… | top users | synonyms

3
votes
3answers
828 views

Why isn't C's most basic printing function named `print` instead of `printf`?

AFAIK, C does not have a print function. The most basic we can get is printf. So, is there a reason why this function is not simply named print, instead of printf? Note that this question is about ...
-2
votes
0answers
13 views

How to write C for POSIX?

If I want to write my C for POSIX, which compiler flags should I comply with? -ansi? -gnu89? Or is it ok with C99? I write a lot of loops this week and I wonder if this is better declaring the ...
8
votes
2answers
79 views

Supporting development for older OS

I am maintaining a large portion of legacy code, written in C. This code was initially written to be comiled against Windows 3 for Workgroups, and later a version for NT was created. This legacy ...
1
vote
2answers
59 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
181 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 ...
-4
votes
0answers
28 views

Valgrind missing error [on hold]

(Original post is here). Please consider the following clearly buggy program: #include <string.h> int main() { char string1[10] = "123456789"; char *string2 = "123456789"; ...
2
votes
2answers
118 views

What are microcontrollers programmed in most in industry? C or Assembly? [on hold]

So recently in school we have started programming klm25z boards using ARM Assembly. I was wondering if in most industry jobs, microcontrollers are really programmed in assembly over C. It seems to ...
1
vote
0answers
84 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 ...
-3
votes
0answers
63 views

How can I oprimize this hash table in C? [on hold]

I want to run greedy algorithm to coloring vertex. A vertex is an unsigned int of 32 bit. And the hash table represents the important part of the graph. I must holds like 1 000 000 vertexes and edges, ...
2
votes
0answers
63 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 ...
0
votes
0answers
61 views

Please let me know more refactoring strategies for my codebase?

I have written a shell command-line interpreter which uses loops and recursion (but maybe not "recursive decent", that usually solves this problem) I want to refactor the function to 4 or 5 smaller ...
28
votes
7answers
3k views

C++ skills higher than C skills? [closed]

I feel that the often seen C/C++ doesn't really describe my skills in my CV. So I'm planning to separate it into advanced C++ knowledge and mediocre C skills. Do you think this is confusing for the ...
8
votes
5answers
4k views

GO instead of C/C++ with cgo

Is it possible to replace C and C++ with Go + cgo and interface frameworks such as Qt or DirectX with Go? Any potential pitfalls I should be aware of? UPDATE: I see that my question was not precise ...
-1
votes
0answers
6 views

How to declare parameters in this case [migrated]

If I have a variable that is declared like this char *string[z][z]; And I want to factor out a for loop from a very large function where the above variable is included, how should the call look ...
-1
votes
1answer
38 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
51 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 ...
-2
votes
1answer
152 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 ...
127
votes
7answers
149k views

When do you use float and when do you use double

Frequently in my programming experience I need to make a decision whether I should use float or double for my real numbers. Sometimes I go for float, sometimes I go for double, but really this feels ...
8
votes
2answers
1k views

Why use typedefs for structs?

in C (ANSI, C99, etc.), structs live in their own namespace. A struct for a linked list might look something like this: struct my_buffer_type { struct my_buffer_type * next; struct ...
0
votes
1answer
299 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 ...
1
vote
5answers
6k views

How to share memory between applications written in C/C++

I'm going through a program written in C/C++ for control in robotics. Basically, three different programs run at the same time, and they communicate via shared memory. Google-ling around I found ...
1
vote
1answer
45 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 ...
2
votes
1answer
157 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 ); ...
2
votes
4answers
316 views

Best and safest API for a function which fills a buffer with variable-length data

I have a function which receives a buffer and returns some data in the buffer. The data can be smaller than the buffer capacity. Which is the best and safest API for this? int fn(void *buffer, ...
2
votes
4answers
485 views

Why is it called a memory leak?

I am a hobbyist programmer, bit of a stickler for terminology, currently learning C and recently came across the concept of Memory Leak. Now, I do understand what it means. Dynamic memory allocated to ...
1
vote
1answer
128 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 ...
0
votes
5answers
1k views

Algorithm for recursive evaluation of postfix expressions

I'm reading Sedgewick's book on algorithms in C and I'm looking for an algorithm to evaluate postfix expressions (addition and multiplication only) without using a stack. I tried to implement one but ...
4
votes
4answers
330 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 ...
9
votes
2answers
321 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 ...
2
votes
3answers
125 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
225 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 their should be avoided. Are static global variables equally bad? In all my projects, I have heavily relied on static global variables. From ...
65
votes
10answers
10k views

Why do C arrays not keep track of their length?

What was the reasoning behind not explicitly storing an array's length with an array in C? The way I see it, there are overwhelming reasons to do so but not very many in support of the standard ...
4
votes
1answer
76 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 ...
0
votes
1answer
77 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 ...
19
votes
1answer
440 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 ...
38
votes
3answers
130k views

Android development using C and C++ [closed]

I am a C, C++ developer. I am interested in mobile development. I want to know how can I develop Android apps using C and C++, I have read that they are providing a kit for C, C++ developers but it ...
0
votes
0answers
8 views

AVX2 method to average 4x4 block of UINT16s [migrated]

Consider the code snippet: uint16_t ave_uint16_4x4_matrix(int xx, int yy, uint16_t **mat) { register uint32_t tot=0U, xi, yi; // Sum 4 by 4 square for(yi=yy; yi < yy+4; yi++) { for(xi=xx; ...
9
votes
3answers
328 views

When should a trig function, with a degree argument, return -0.0?

In creating trig functions my_sind(d), my_cosd(d), my_tand(d), that used a degree argument rather than a radian one and provided exact answers at multiples of 90, I noticed that the result was ...
3
votes
2answers
118 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 ...
17
votes
4answers
1k views

Is it necessary to follow the standard, take the C standard for that matter?

There are some very experienced folks on Stack Overflow who always talk about the C standard. People seem to not like non-portable solutions, even if they work for me. Ok, I understand that the ...
2
votes
3answers
162 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
86 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 ...
60
votes
13answers
31k views

What's the benefit of object-oriented programming over procedural programming?

I'm trying to understand the difference between procedural languages like C and object-oriented languages like C++. I've never used C++, but I've been discussing with my friends on how to ...
3
votes
2answers
201 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 ...
12
votes
2answers
2k views

Why can't arrays be passed as function arguments in C?

Following this comment, I've tried to google why, but my google-fu failed. Comment from link: [...] But the important thing is that arrays and pointers are different things in C. Assuming ...
0
votes
1answer
156 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
91 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
153 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
96 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
88 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 ...