Skip to main content
The 2024 Developer Survey results are live! See the results

Questions tagged [c]

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

6 votes
2 answers
513 views

When the stack frames become computationally expensive

I've been experimenting with different data structures and algorithms in Python, Java and C to see in what circumstances function/method inlining could bring meaningful gains in terms of the execution ...
ipastusi's user avatar
  • 171
2 votes
1 answer
103 views

C++: Good approach to handle libxml2 resource management in a wrapper

I try to write a C++ wrapper to a well-known C library, libxml2. In libxml2, an xmlDocPtr represent an XML document and xmlNodePtr represents a node. An xmlDocPtr contains a root xmlNodePtr and every ...
Zoltán Várnagy's user avatar
2 votes
3 answers
179 views

How to decouple spagheti code for unit tests [duplicate]

A little background on the project: we as a company receive a spaghetti source code, and into that we add even more spaghetti code. So with that I want to say that complete restructuring and ...
Tomáš Viks Pilný's user avatar
0 votes
4 answers
388 views

Is it a bad practice to return an enum without an enum return type?

I'm specifically asking about C. Example: enum numbers { EVEN, ODD }; int isFiveEvenOrOdd(void) { if (5 % 2 == ODD) return ODD; else return EVEN; } int main(void) { printf("%...
OnyxWingman's user avatar
4 votes
4 answers
994 views

Is updating a macro value in the Xcode preprocessor's macros violating the open–closed principle?

For example, for some Xcode projects, if I have some places that defines a number at some .cpp files: const int PAGE_MAX=5; and a new requirement comes that needs to change PAGE_MAX, I need to modify ...
wcminipgasker2023's user avatar
2 votes
4 answers
325 views

How would I go about writing my own implementation of Win32 functions?

So I am currently coding a C program for Windows and come across a little bit of a problem. I've been compiling using the mingw-w64 toolchain. In my program, I am attempting to remove as many ...
baron's user avatar
  • 55
0 votes
1 answer
129 views

Elegant way in C to store many parameters with default value and current value in embedded flash

I'm programming an embedded system that has a number of user configurable parameters, which are stored in flash memory. I have to store a default value for each parameter as well as the user settings. ...
jusaca's user avatar
  • 175
2 votes
1 answer
235 views

C++ vs C console output idioms

I'm struggling to understand pros and cons of the C++ and C approaches to console output. C++ uses the stream approach with concatenation of operator<<, while for "C approach" I mean a ...
Nicola Mori's user avatar
0 votes
2 answers
177 views

How might encapsulated source be broken into into multiple files?

I have a project where there is a primary, high-level, opaque struct with many functions that operate on it. Maybe I am simulating a CPU. How might the corresponding source code be organized? One way ...
Ana Nimbus's user avatar
1 vote
2 answers
145 views

How to handle errors of pthreads fundamental lock und unlock functions?

I am writing a little C library for the Raspberry Pi for controlling 433MHz transmitters/receivers. While receiving data the whole application would block, so I decided to put this code into a ...
blackdog's user avatar
25 votes
2 answers
6k views

Why is the term "string" so often abbreviated as "sz"?

A pattern I have noticed in many big C and C++ programs - including Microsoft Windows (REG_SZ type in Registry) and Valve's Source SDK (names of practically every string variable) - is that "sz&...
AcinonX's user avatar
  • 613
3 votes
2 answers
605 views

Maintaining global states in a recursive function

I am writing a recursive function. Some of the parameter data is different for each recursive call but some of the data only need to have one copy existing at any one time during the recursive call. ...
CPlus's user avatar
  • 1,189
0 votes
0 answers
56 views

Are type, constant/static/global, and pointer prefixes still necessary in C coding standards, considering the capabilities of modern IDEs? [duplicate]

Our coding standards for C include various prefixes for data types, constants, static/global variables, and pointers. These prefixes were originally introduced for code review purposes, but with the ...
Cem Polat's user avatar
  • 127
21 votes
4 answers
9k views

In C, if I am passing a file descriptor to a function, should I close it in the function or in the place where I called the function?

I have a situation like the following: int fds[2]; pipe(fds); // Write lots of stuff into fds[1] close(fds[1]); do_stuff(fds[0]); // Should I close fds[0] here or at the end of do_stuff? Which one ...
eem's user avatar
  • 329
10 votes
5 answers
12k views

Why is int in C in practice at least a 32 bit type today, despite it being developed on/for the PDP-11, a 16 bit machine?

For background, the question is to prepare some training material, which should also should explain a bit why the things are the way they are. I tried to get some idea of how C began based on this ...
Torsten Knodt's user avatar

15 30 50 per page
1
2 3 4 5
88