Skip to main content

Questions tagged [c]

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

Filter by
Sorted by
Tagged with
2 votes
4 answers
160 views

I'm developing a multithreaded game server (C/TCP). I need to send a list of 50-100 available games to a console client. Option A: Send 50-100 separate messages, using send() for every single ...
dok's user avatar
  • 313
1 vote
2 answers
169 views

I’m writing a multiplayer server in C using sockets and pthreads. The project is separated by responsibility: server.c/.h → networking (socket, bind, listen, accept, thread creation) player.c/.h → ...
dok's user avatar
  • 313
1 vote
2 answers
148 views

I’m writing a multiplayer server in C using sockets and pthreads. The project is separated by responsibility: server.c/.h → networking (socket, bind, listen, accept, thread creation) player.c/.h → ...
dok's user avatar
  • 313
4 votes
6 answers
857 views

It is said that C's type system is unsound, which means that it has "false negatives", it tells the programmer everything is fine, but then the code fails at runtime. for example, "the ...
Ghassen's user avatar
  • 185
-1 votes
1 answer
142 views

So I was coding in C for a while now, getting used to language syntax and different styles. Implemented a couple of simple data structures, algorithms and tried my skills in making Minesweeper clone. ...
MightyBeast's user avatar
1 vote
3 answers
721 views

I have a source file that is used by other sources so it has a header file. If in the header, there are types used that needs inclusion of other headers, I'm better to include this header in its ...
mltm's user avatar
  • 121
1 vote
3 answers
578 views

As far as I can tell, the strings "It's me" and "It\'s me" are always identical. There seems to be no reason when a programmer needs to escape '. Yet, I could not find and ...
user2468852's user avatar
1 vote
3 answers
373 views

In an embedded system, I require a watchdog to be able to pass ESD qualifications. Having no experience with watchdogs, I went through this Memfault article. I liked the events "registration"...
DarkFranX's user avatar
  • 119
2 votes
1 answer
174 views

The software architecture literature has lots of information on software connectors as in component and connector views of architecture. What kind of connector is a file descriptor? I noticed in the ...
Passeris's user avatar
6 votes
4 answers
738 views

In Postgres, it used to be quite common to use a 4-byte integer auto field for primary keys, until it started becomming somewhat common to run into the 2147483647 limit of 4-byte integers. Now, it's ...
orokusaki's user avatar
  • 1,093
1 vote
3 answers
436 views

I have a C codebase with function calls made through function pointers. I tried using LLVM AST and IR with Python to generate a function call graph, but handling the function pointer calls requires ...
Sam's user avatar
  • 165
0 votes
2 answers
303 views

For, e.g. determining an amount of memory that is safe to allocate for processing file or device with this type of I/O loop: HANDLE hFile /* = file open with GENERIC_READ */; LARGE_INTEGER liSize; ...
Govind Parmar's user avatar
1 vote
5 answers
390 views

Consider that I've implemented SHA-256 hashing in C as incrementally updated IUF (init-update-finalize) working context and 3 subroutines. To use it in free-standing environment, or to efficiently use ...
DannyNiu's user avatar
  • 374
7 votes
2 answers
734 views

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 ...
user avatar
3 votes
1 answer
212 views

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
270 views

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
3k views

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
1k views

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
509 views

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
244 views

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
3 votes
1 answer
305 views

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
209 views

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
467 views

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
7k views

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&...
Bunabyte's user avatar
  • 643
3 votes
2 answers
1k views

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,219
0 votes
0 answers
59 views

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
10k views

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
13k views

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
1 vote
1 answer
1k views

I am working on a simple client server program in C in which multiple clients will be connected to a single server. Clients will submit operations/actions to the server and the server will process ...
nick2225's user avatar
  • 157
1 vote
3 answers
250 views

In a spare-time project of mine, I implemented RSA public-key cryptosystem. Because the official PKCS#1 standard specify key formats in terms of ASN.1 syntax and DER/BER coding, which is a coding with ...
DannyNiu's user avatar
  • 374
0 votes
1 answer
272 views

In my experience, it is customary to place local variable declarations at the beginning of their scope. Several questions in this forum ask whether this needs to be so, and their answers tend to agree ...
Severo Raz's user avatar
7 votes
2 answers
2k views

How can I make DRY (lacks repetitive patterns) code that also avoids inefficiencies from using intermediate values in a calculation that might not need to be used? Here is an example: In this code, I ...
CPlus's user avatar
  • 1,219
27 votes
6 answers
28k views

I have been told that Rust is both safer and faster than C++. If that is true, how can that be even possible? I mean, a safer language means that more code is written inside the compiler, right? More ...
euraad's user avatar
  • 403
0 votes
1 answer
196 views

In C programming, I have a set of information, and I have to ways of providing it to user: construct a data structure and provide it as an object. write a function to read them out and return them. ...
DannyNiu's user avatar
  • 374
1 vote
1 answer
356 views

I frequently use the concept of Active Objects (https://www.state-machine.com/active-object) combined with state machines when designing code. The key idea behind these is that only "events"...
Patrick Wright's user avatar
0 votes
3 answers
2k views

I'm building an HTTP server in C using epoll and pthread. The idea is to have an event loop in the main thread monitoring file descriptor and a thread pool to handle computationally-expensive ...
Richard H. Nguyen's user avatar
4 votes
1 answer
341 views

I am working with a library that is somewhat poorly written. In order to function, it requires several global variables to be declared and sometimes even maintained by my own code. I really don't ...
Infinite_Maelstrom's user avatar
-1 votes
1 answer
156 views

I just happened to stumble across the following question on stack overflow: In gatomic.c of glib there are several function declarations that look like this: gboolean (...
Marco's user avatar
  • 377
1 vote
4 answers
853 views

I'm required to write the Low-Level Requirements of a Software Component which shall perform signal processing over arrays of 200k elements of integers/floats which lives in the main memory of the ...
Sam's user avatar
  • 31
1 vote
3 answers
250 views

I was programming today and encountered something that just feels like I'm doing something wrong (maybe?). I've encountered this situation before, but I wanted to reach out and ask if there's a better ...
jrgilman's user avatar
  • 121
1 vote
0 answers
100 views

Context I'm designing the software architecture of a safety critical software written in C, under DO-178C (DAL A) and with a Code Standard based on MISRA-C 2012, but no fully compliant. It is the ...
Sam's user avatar
  • 31
4 votes
1 answer
361 views

I'm reading the book The Secret Life of Programs by Jonathan E. Steinhart. In it, he mentions in passing: many consider the handling of whitespace in Ruby to be a replay of of a mistake in the ...
tsvallender's user avatar
0 votes
2 answers
264 views

It has caught my attention that both arguments of fopen are both restrict-qualified. It's been that way since C99. What does this achieve? If I have: const char *path = "foobar"; const char *...
Kaz's user avatar
  • 3,702
0 votes
3 answers
973 views

Given a state machine that implements a certain protocol. I need multiple instances of this protocol running, so I create multiple instances of this state machine. Each instance is associated with a ...
PieterV's user avatar
  • 233
3 votes
2 answers
3k views

I am working on improving the code quality and portability of my C library, specifically a ring buffer implementation, that will be used in larger applications. I have encountered a dilemma regarding ...
Usman Mehmood's user avatar
3 votes
1 answer
444 views

I've been learning C recently. I've completed a number of coding challenges on websites like codewars in C, and I always find myself wishing I had something like Python's flexible data structures. In ...
Connor's user avatar
  • 159
7 votes
2 answers
4k views

In C you cannot assign arrays directly. int array[4] = {1, 2, 3, 4}; int array_prime[4] = array; // Error At first I thought this might because the C facilities were supposed to be implementable with ...
CPlus's user avatar
  • 1,219
0 votes
2 answers
180 views

Given the following hierarchy of objects: a keyed collection of ClassA objects, where each ClassA object contains a keyed collection of ClassB objects and each ClassB object contains a keyed ...
PieterV's user avatar
  • 233
0 votes
1 answer
86 views

I have the following code in C that reads data off a char array and makes decisions on what variables should some pointers point to. char preset1[20]; char preset1Name[20]; int preset1Temp; int ...
HFOrangefish's user avatar
2 votes
1 answer
2k views

Most useful or reasonably complex applications need to save data such as user settings or saved games or browser history. I have been working on applications and games in C or C++ but I am not sure ...
CPlus's user avatar
  • 1,219

1
2 3 4 5
27