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
3 votes
2 answers
5k views

Finding header files

A C or C++ compiler looks for header files using a strict set of rules: relative to the directory of the including file (if "" was used), then along the specified and default include paths, fail if ...
rwallace's user avatar
  • 1,188
3 votes
3 answers
2k views

Is there any merit to using `union` to create an alias?

I've inherited a bit of code and saw something new. They have a data structure definition out in a .h file, and in various local files they'll declare: union globalStructOstuff localVar; Is there ...
Philip's user avatar
  • 6,762
3 votes
5 answers
893 views

Naming convention for functions that mutate arguments vs creating a new object

Take the following signature BigInt* addBigInt(BigInt* arg1, BigInt* arg2); Traditionally, the safest way to implement this function would be for it not mutate the arguments, and would necessarily ...
Chad Harrison's user avatar
3 votes
2 answers
376 views

malloc on different platforms

I am testing a red-black tree implementation (repository) and I find that with Windows 10 and gcc, malloc starts returning NULL after inserting approx. 50 million nodes but on Linux it works at least ...
Niklas Rosencrantz's user avatar
3 votes
3 answers
2k views

How useful is JNI in android?

In java/android we can call code written in the c/c++ language for execution speed advantage. I have heard of Ahead Of Time compilation which (as far as i know) compiles the entire application to ...
pebble's user avatar
  • 141
3 votes
2 answers
372 views

Protecting Structure from corruption

I am developing a safety critical embedded system and I am programming in C. We have a set of const structure declared in memory and they hold some critical data. I want to make sure that any of ...
Swanand's user avatar
  • 133
3 votes
4 answers
823 views

Equivalent of C library functions

In C, almost everything requires a function. What nags me is that I don't know exactly what's going on. If there was no msvcrt.dll file, my C programs would all break because that's where all the ...
Garhoogin's user avatar
3 votes
1 answer
133 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 ...
hgiesel's user avatar
  • 791
3 votes
2 answers
2k views

Complex iterators in C

note: this was originally asked on SO. Part of my current project involves iterating over sequences that don't necessarily exist. For example, I have something similar to a relational database in ...
Gage's user avatar
  • 131
3 votes
1 answer
427 views

(almost) Pure C instead of C preprocessor [closed]

Why isn't (almost) pure C used instead of the C preprocessor? Sure I understand it would be a little more verbose. For example: #define PI 3.14159 If we had regular C as preprocessor language, the ...
nijoakim's user avatar
  • 157
3 votes
2 answers
7k views

Infinite while loop CPU usage

I'm coding an script in C, which is going to check constantly an array of events, the idea is to check if the Date and time of certain event is equal to de current time and trigger something, i'm ...
David T's user avatar
  • 43
3 votes
1 answer
234 views

Evaluation order of the expressions

The C Programming Language by K & R states that C, like most languages, does not specify the order in which operands of an operator are evaluated. (The exceptions are &&,||,?: and ','). ...
user1369975's user avatar
  • 1,289
3 votes
2 answers
1k views

Send stdout or stderr to a new thread

For performance issue I want the logging send to a new thread. While the main program can work, the new thread can write the error or other messages to a file without effect to the main program. How ...
Thor's user avatar
  • 31
3 votes
2 answers
5k views

How far is the trail from Java to C / C++? [closed]

I want to find out how easy or hard the transition to C / C++ is for a mid-experienced Java programmer. I've already read the questions about "C++ for Java Programmers" and "Is it necessary for Java ...
f4lco's user avatar
  • 191
3 votes
4 answers
475 views

Should functions depend on other functions?

Suppose I have a function to log error messages printError(). Suppose I have another function which might throw an error, doSomething(). Should doSomething() implement its own error logging or depend ...
404 Name Not Found's user avatar
3 votes
1 answer
5k views

Declaring functions using macros?

Is it generally encouraged or discouraged to create a pre-processor macro in C, that facilitates the creation of many functions with the same signature (differing only in name). For instance, instead ...
Jon Deaton's user avatar
3 votes
1 answer
179 views

What's the best architecture to mix C code and a ASP Classic website

I have to create a real-time display. On this display I have to get the numbers from an existing business logic component (written in C) and display these Live on a classic ASP-page (legacy app). ...
MiMeng's user avatar
  • 67
3 votes
2 answers
5k views

Implement inheritance in C

I was working with GTK in one of my projects and I noticed that the library supports inheritance. As you can type-cast a child struct to its parent struct and vice versa. Other than GTK I've never ...
Dellowar's user avatar
  • 508
3 votes
1 answer
280 views

How to compare C and CUDA performance fairly?

I have developed a CUDA code that is a reimplementation of a (CPU only) C code. I would like to benchmark the performance of these two programs. I am wondering how to do benchmarking well in this ...
Vince Varga's user avatar
3 votes
6 answers
3k views

Can a data hold multiple values?

I'm a beginner and I'm following a course on C programming. In my book,a variable is defined as a memory space that stores a single unit of data (datum). Is a data structure considered to be a single ...
Othman's user avatar
  • 299
3 votes
1 answer
320 views

Would it be a good idea to use variadic functions in a C API as a means of preserving the ABI?

Say you're designing a C API, and one of your big concerns is ABI stability (it's going to be deployed as a shared library, or whatever). You have a function exported int foo_bar(int a, int b, int*...
Bwmat's user avatar
  • 779
3 votes
1 answer
535 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 ...
fsasm's user avatar
  • 133
3 votes
1 answer
275 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 ...
Philip Stuyck's user avatar
3 votes
1 answer
2k 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 ...
JavaProphet's user avatar
3 votes
1 answer
1k 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 ...
Joe's user avatar
  • 359
3 votes
1 answer
119 views

Are there any problems with defining a single-source "module" in C using conditional compilation to separate the "header" from "source"

I'm writing a project that I want to keep small in the sense of being very densely-coded and a single source file. But it's growing large enough that navigating the file is becoming tiresome, so I ...
luser droog's user avatar
3 votes
1 answer
3k views

C Module - Where to put prototypes and definitions that do not belong to the public interface?

Since I am mainly an Electrical Engineer, forgive me if I am somewhat off with some terminology. I am currently programming a display driver/interface module. And like so many times before, I have ...
Rev's user avatar
  • 213
3 votes
4 answers
2k 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, ...
Conrado's user avatar
  • 131
3 votes
2 answers
337 views

"continue" and "break" for static analysis

I know there have been a number of discussions of whether break and continue should be considered harmful generally (with the bottom line being - more or less - that it depends; in some cases they ...
Bill's user avatar
  • 609
3 votes
3 answers
513 views

Do simple accessors and mutators benefit from commented block headers?

Short Question Is it necessary to add the function header comments for simple accessors and mutators? Example u8 OBJ_get_state_x(void) {return obj.state_x;} void OBJ_set_state_x(u8 x) {obj....
Adam Lewis's user avatar
3 votes
2 answers
353 views

What pitfalls and gotchas commonly occur when beginning with Parallel and Concurrent Programming with C? [closed]

It roughly three weeks I will be taking a Parallel programming class that is taught using C for the assignments. I have a fairly strong interest in the subject at present and my C skills aren't ...
user avatar
3 votes
1 answer
2k views

Using a preprocessor macro to wrap functions?

I have multiple use cases where I need to call an "entry" function, do a bunch of stuff, and then call an "exit" function. (In my case, "entry" is enabling a chip select ...
fearless_fool's user avatar
3 votes
1 answer
2k views

C programming - Advantages and disadvantages of using opaque pointers for structure handling

Which are the main advantages and disadvantages of me using opaque pointers for all my structures? I have been thinking about using this approach and here are some trivial thoughts that I have: ...
Pedro Freitas's user avatar
3 votes
1 answer
198 views

Wrapper function or aliasing with a union?

I have a structure that might have 2 more members depending on a preprocessor variable. struct foo { int m1; // ... (other members) #ifdef MORE_MEMBERS int m2; int m3; #endif }...
devil0150's user avatar
  • 159
3 votes
1 answer
10k views

Is there any technical reason to typedef void? [closed]

No opinions, please. Is there any technical reason to typedef void? My current company and my last both have typedef void XYZ_void; where XYZ is the project name. I can understand a typedef for ...
Mawg's user avatar
  • 4,204
3 votes
2 answers
1k views

Advice for simple communication protocol (iPod and Arduino)

I connected iPod with Arduino using serial (UART) connection. Arduino sends 0-1023 number (so it's two bytes) as it's samples light sensor value. I'm asking about advice about simple and reliable ...
kesrut's user avatar
  • 175
3 votes
2 answers
2k views

C Equivalent of Perl Unpack & Pack

I have some perl code that uses pack and unpack to transform the data in a way that I don't understand. $unpacked_data = pack('b*', join('', unpack('(b7)*', $packed_data))) Where $packed_data = a ...
Meep's user avatar
  • 133
3 votes
1 answer
975 views

Is the Leptonica implementation of 'Modified Median Cut' not using the median at all?

I'm playing around a bit with image processing and decided to read up on how color quantization worked and after a bit of reading I found the Modified Median Cut Quantization algorithm. I've been ...
TheCodeJunkie's user avatar
3 votes
4 answers
190 views

Source control workflow for managing a software platform

I'm in charge of a software platform, written in C, that is used to provide a variety of projects to clients. I am trying to improve the workflow for people using this platform, and looking at ...
asc99c's user avatar
  • 151
3 votes
2 answers
752 views

API for data structure with indices, size_t vs int?

For a data structure with indices (e.g. an array list, a dynamic array, etc...), should the indices be of type size_t or int? Is there a clear reason to use one over the other? fooGetByIndex(struct ...
Wingblade's user avatar
  • 207
3 votes
1 answer
263 views

State propagation(bottom-up) in multi-walk tree

Using the Tree representation(mentioned below), typedef enum {Running, Warning, Critical}Status; struct TreeNode; typedef struct List{ int childCount; struct treeNode **childList; }List; ...
overexchange's user avatar
  • 2,265
3 votes
1 answer
130 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 ...
Vorac's user avatar
  • 7,129
3 votes
1 answer
255 views

Parallel Threading in Multi-Language Software?

I'm developing a software that contain many modules/Daemon running in parallel manner, what i'm looking for is how to implement that, i cannot use Thread because some of those modules/Daemon are ...
Marwen Trabelsi's user avatar
3 votes
2 answers
2k views

Shared FIFO file descriptor

is ok to open fifo with one FD and share it with multiple threads? or is it better to have multiple fds opened for the same fifo and share these fds with the threads? BTW, I'll be doing write and read....
poly's user avatar
  • 407
3 votes
5 answers
4k views

Is Operator Overloading supported in C

When I read about the LCC (Windows) compiler, I found out it has the implementation for operator overloading. However, after a bit of Googling, I've confirmed that operator overloading isn't ...
caramel1995's user avatar
3 votes
1 answer
2k views

When should I use static variables with primitive types?

Recently I came across the question NSString: Why use static over literal? and in the comments arrived a new question. In Objective-C there some "special" types that are just maps to C primitives. ...
Felipe Cypriano's user avatar
3 votes
1 answer
266 views

Publisher-Subscriber architecture with central registry

Problem description Publisher-Subscriber architecture with a central registry where agents can either promote their capabilities or search for a given capability. The project must be developed with ...
Dayrona's user avatar
  • 139
3 votes
1 answer
1k views

Embedded software architecture - What is the difference between DAL and HAL?

I'd like to know what the difference is between hardware abstraction layer (HAL) and data abstraction layer (DAL) when speaking about embedded software. I might have the abbreviations wrong though... ...
traducerad's user avatar
3 votes
1 answer
512 views

What tasks does a memory barrier enforces other than preventing the re-ordering of instructions?

I know that a memory barrier prevents the re-ordering of instruction from before to after and from after to before the memory barrier, for example if I have the following instructions: instruction 1 ...
Christopher's user avatar
  • 2,039
3 votes
1 answer
3k views

How does a dynamic library's references to a global variable get translated once in the running app?

If a dynamic library exports the address to a global variable defined within the library, how are accesses to that variable translated during dynamic linking so that a running application can interact ...
Victor's user avatar
  • 947

1
12 13
14
15 16
27