Tagged Questions

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

learn more… | top users | synonyms

2
votes
3answers
181 views

Why are there two different kinds of linking, i.e. static and dynamic?

I've been bitten for the n-th time now by a library mismatch between a build and deployment environment. The build environment had libruby.so.2.0 and the deployment environment had libruby.a. One ruby ...
4
votes
1answer
584 views

Why are most GNU's software written in C [closed]

I am a Java developer, and I rarely write GUI program in C. However, I noticed that many GNU's projects, such as PSPP, R, Dia, etc., are written in C, instead of Java or C++. I personally don't mind ...
-2
votes
4answers
226 views

Benefits of porting C library to C++ [closed]

Say we take any C library such as libpng or libvorbis and convert it so that it compiles as C++ (only the minimum changes to make it compile as C++ code). Can the compiler do extra optimizations when ...
1
vote
2answers
333 views

“bug” in C++11 text by Stroustrup?

I found an apparent contradiction in the c++ text having to do with the result of the c_str() function operating on std:strings (in my copy, the definition and contradiction are on p1040). First it ...
1
vote
1answer
126 views

Should I implement a function or a method?

Once in a while I encounter a C function in my colleagues' code. Mostly it is in some helpful objective categories, and those functions are mostly an internal calculation of something or a ...
0
votes
3answers
210 views

How are negative signed values stored? [duplicate]

I was watching this video on the maximum and minimum values of signed integers. Take an example of a positive signed value - 0000 0001 The first bit denotes that the number is positive and the last ...
15
votes
1answer
584 views

How to effectively cooperate in a team having mixed background/mindset regarding OOP? [duplicate]

I've been recently assigned for a new high-performance C++ project (finance) together with 3 other guys who, like, me, refer to themselves as "primarily C/C++ programmers", meaning, all of us have ...
21
votes
7answers
3k views

Writing in C for Performance? [closed]

I know I have quite frequently heard that C typically has a performance advantage over C++. I didn't really think anything else of it until I realized that MSVC doesn't even seem to support the newest ...
0
votes
3answers
506 views

comparison of floating point numbers vs. comparsion of Integers in C [closed]

Does comparison of floating point numbers takes (considerably) longer time than comparison of Integers in C? I just wrote a C program of heap sort to sort floating point numbers. I am on ubuntu ...
4
votes
3answers
107 views

Is allocating objects from a memory-pool a security anti-pattern?

In the wake of the heartbleed bug, OpenSSL has been rightly critizised for using its own freelist. With plain-old malloc, the bug would have almost certainly been found long ago. However, some kind ...
0
votes
0answers
19 views

how to find average bits per symbol using huffman code? [duplicate]

I'm trying to write a program in c for Huffman coding, but i stack.In input i have: Sample input: 4 //here i scan how many letters i have A 00 // and for everyone i scan how they are coded in ...
55
votes
10answers
6k 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 ...
1
vote
0answers
194 views

using flat file vs sqlite db for frequent data grabbing in a cron job

I have some automated task to be done using certain types of logs generated on the server end of each day. Log files contains specific machine identification "MAC" that is to be re-written in to ...
1
vote
1answer
138 views

How to implement an algorithm out-of-core?

I want to implement a parallel clustering algorithm "out-of-core" in CUDA. My CPU has 12GB of RAM and GPU has 4GB of it. What I want is that the entire dataset should be on the disk, and I can pick ...
5
votes
1answer
163 views

At ping, why do we have to do array copying instead of passing on the source array that the client sent to us?

So I have been googling about this OpenSSL heart-bleed thing and somehow sees that it is caused by the heartbeat extension which requires client to ping the server to show its aliveness and it all ...
3
votes
2answers
139 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 ...
3
votes
2answers
198 views

How to manage memory in C interface for C++ implementation considering c++11?

I have a library implemented in C++ which has a C interface. This C interface is, for all intents and purposes, the only way to use this library. C++11 seems to discourage the use of raw pointers but ...
2
votes
3answers
87 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, ...
0
votes
2answers
60 views

Use one or multiple files for graphics properties?

I'm creating a 2D game in plain ANSI-C using SDL2. I'm planning to let users create their own graphics. So, to achieve this, I'll use an information file which will hold some data such as Width, ...
0
votes
3answers
102 views

Looking for a certain datatype if it exists

I'm looking for the kind of a certain datatypes. The main idea of this datatype is to describe a productionline containing several steps. Each step should be represented as a "vertex" containing an ...
0
votes
5answers
130 views

What conclusion to be drawn from no difference in generated assembly from 2 rather different programs?

I might not have had a counterexample when I got the reply "A pointer is just an address, what's the difficulty?" but I didn't really buy such a simple explanation and at assembly code it's not ...
3
votes
2answers
295 views

Are (C) object files created with different compilers binary-compatible?

I understand that C++ compilers are not compatible with each other. However, I was unable to find anything on this topic for C in particular. I know that the C standard leaves a lot of room for ...
0
votes
1answer
164 views

Algorithm for base-conversion in C?

I put in this code which does what it's supposed to do, but perhaps there is a better or more general approach? I'm converting a 4-digit base 10 number e.g. "11" to base 16 e.g. "17" (which gets ...
0
votes
3answers
159 views

How can I handle this string concatenation in C in a reusable way

I've been writing a small C application that operates on files, and I've found that I have been copy+pasting this code around my functions: char fullpath[PATH_MAX]; fullpath[0] = '\0'; ...
2
votes
2answers
346 views

Representing a deck of cards in C (not C++)

So far my best ideas have been as fallows A) Represent a "card" in one structure and have a "deck" in another a deck being an array of 52 cards and a card being 2 chars one for and rank one for suit. ...
1
vote
4answers
299 views

How do you call one program from another?

What I'm wondering is how running programs communicate with each other, and if someone could post some sample code for how to do this, so I can try it out myself, just for educational purposes. For ...
1
vote
2answers
204 views

What is the underlying mechanism behind va_list and where is it defined?

http://www.cplusplus.com/reference/cstdarg/va_list/ According to the above link, va_list is an argument or parameter used in some macros - va_start, va_arg, va_end. These macros are present in the ...
1
vote
1answer
189 views

What is this programming style? “Monoid-ic”?

In a moderately old blog post, Conal Elliot makes an interesting (if less than serious) argument that C is a purely functional language, by drawing a parallel between the combination of the C ...
1
vote
0answers
132 views

How to extract the active code path from a complex algorithm

I have been puzzled lately by an intruiging idea. I wonder if there is a (known) method to extract the executed source code from a large complex algorithm. I will try to elaborate this question: ...
1
vote
1answer
149 views

Global variable vs. local-static variable for storing state

I am writing an application for my graduation coursework, in C, using GTK+ UI library. Sometimes I ask for user input, which I need to save for later use. The doubt comes on how to store this data. I ...
0
votes
2answers
295 views

Shared source file between two parts of project [closed]

I have the following sort of directory structure: part1 build src part2 build src Now I have a header file that I would like to include in both parts of these projects, it will ...
3
votes
2answers
283 views

Speed difference between VM-based and compiled code [closed]

Not so long ago I was told by a senior academic that, these days, VM-based code could run nearly as fast as compiled code, but my own experience is that compiled code runs several orders of time ...
1
vote
2answers
240 views

Creation of an Assembler [closed]

I've always been interested in how programming languages are created, so for the past 8 months I've been researching, practicing and more about the creation of compilers. I've been able to quite ...
5
votes
3answers
474 views

How to teach pointers to beginners in C? [closed]

I'll hold a little presentation about C-Pointers in a small group of people with beginners programming skills, with no CS background. Just people who would like to learn something about coding and ...
2
votes
1answer
143 views

OOP in C: which of these two approaches is closer to a cannonical solution? [closed]

Here are the two approaches to writing OOP (as in "we have objects and we can instantiate any number of them, each having it's own private data"). The language is C and the platform is embedded ...
4
votes
3answers
228 views

How do I maintain consistency between hard-coded values in different files?

I have a C source file and another (non-code) file in a project which contain the same hard-coded value. Ideally, the value would be specified in only one location and be copied to the other location ...
1
vote
3answers
316 views

Choice between 1-dimensional and 2-dimensional array

I'm implementing the Chessboard class to represent the chessboard. I've to implement the transformations (reflections and rotations) on the chess board possible. The possible transformations includes ...
9
votes
5answers
343 views

How to make it obvious that a function is being accessed from the outside?

This is a C specific question. I am trying to keep everything possible inside the translation unit boundaries, exposing only a few functions through the .h file. That is, I am giving static linkage to ...
0
votes
2answers
86 views

Should functions be prepared for overlapping buffers?

So I have a function in C like this: void crunch(const char *in, char *out, size_t inLen, size_t outLen) { //... } If the two buffers overlap, the function may mess up the input buffer as well, ...
0
votes
1answer
168 views

Is TCP message order still guaranteed when using async IO

Here the scenario I'm imagining. Two messages are transferred, both will require 2 packets each (I know you don't deal with packets directly with TCP, but on the IP level each message will consist of ...
1
vote
2answers
432 views

How do we go from assembly to machine code(code generation) [closed]

I know this is abstract as it's all about signals and switch - (electronics) - underneath, but is there a easy way to visualize the step between assembling code to machine code. For example if you ...
0
votes
3answers
192 views

ANSI C pointers corrupted values

I am working on ANSI C and having some issues with the pointers. That is that after a point in my program the pointer's values change without me interfering, is something like overwriting them. I ...
1
vote
1answer
244 views

Next power of 2 for a number (in search for better “bit-twiddling” way)

I just wonder if there exists better (i.e. faster?) way to get the next power of 2 for a given number than the following one (maybe some better sort of "bit-twiddling" hack is possible?) ... static ...
1
vote
3answers
223 views

C API in C++ with RAII, two alternatives to implement error handling (Exceptions)

I have an API written in C, which produces a result by returning a pointer to allocated memory. For using it with C++ (C++11) I've wrapped the function calls in objects, which keep the result in a ...
1
vote
1answer
177 views

Is learning different programming languages from different categories good? [closed]

I have read some posts regarding learning different programming languages or not. Most of the answers indicate that learning more than one programming language increase our horizon as a programmer and ...
-1
votes
1answer
121 views

Creating a window to draw pixels in [closed]

I'm creating a fictional architecture and other fictional components for this computer/emulator. I'm facing an issue, this being the virtual display. I need to be able to create a Window in which my ...
3
votes
1answer
188 views

How can Lisp produce an iterative process from a recursive procedure?

I am starting to learn Lisp, using the SICP book. The authors mention that a procedure (i.e. function) can be recursive or iterative. Additionally, the process those procedures will generate will also ...
2
votes
1answer
117 views

Is the result of strcmp the same on all machines and compilers?

Code: #include <stdio.h> #include <stdlib.h> #include <string.h> int main() { int n = strcmp("hello","help"); printf("%d\n", n ) ; return 0; } Result: -1 Does ...
0
votes
0answers
58 views

wrap mysql API for gui use

Some time ago now, I've written a command-line tool, that connects to MySQL, and through a series of commands, does all sorts of good stuff. It was originally intended to be used by myself and, ...
3
votes
2answers
397 views

using unsigned integers in c, c++

I have a very simple question that baffles me for a long time. I am dealing with networks and databases so a lot of data I am dealing with are 32-bit and 64-bit counters (unsigned), 32-bit and 64-bit ...