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

learn more… | top users | synonyms

1
vote
1answer
110 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
138 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 ...
0
votes
0answers
10 views

Sempahores and Mutex Lock [migrated]

two scenarios, what is the difference. I cannot understand which to use. It seems that they basically do the same thing. pthread_lock(&mutex) critical section pthread_unlock(&mutex) vs ...
-2
votes
0answers
20 views

Standard DES encryption lib or package for C [closed]

Is there a DES encryption lib or package for C that is similar to the Java DES package? thanks, John
3
votes
2answers
63 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
115 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
1answer
122 views

Advantages and Disadvantages of C CGI over PHP? [closed]

I've developed a lot of websites with PHP but sometime after learning C programming I found out that it's possible to do the same thing using C CGI. But I still don't know if it will be worth ...
-4
votes
0answers
20 views

Saving an array to a binary file in C? [migrated]

Suppose I create an m by n matrix in the following manner: double (*myArr)[n] = malloc(m * sizeof(*myArr)); How would I then save that to a binary file? I've tried using fwrite, but I haven't ...
2
votes
3answers
51 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
47 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
1answer
57 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
81 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
194 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 ...
-1
votes
0answers
97 views

Is there a difference between writing/passing value with or without float “f” suffix? [migrated]

I believe I should type less if it's possible. Any unnecessary keystroke takes a bit a time. In the context of objective-C, my question is: Can I type this [UIColor colorWithRed:0 green:0 blue:0 ...
0
votes
0answers
74 views

Adding Very Large Array's in C. Is there a better way to do this? [migrated]

I am writing a stochastic simulation for a yule process. It basically works likes this if you start with a certain number of bins each containing a random number of balls you add another ball to an ...
-1
votes
0answers
32 views

Basic C programming [migrated]

I'm trying to write a program which given a certain number of input will output the product of the listed input (only accounting inputs of 0-9 and ignoring other). For example: input:345 would result ...
0
votes
0answers
48 views

What concept is being exhibited in this macro wrapping? [migrated]

A bunch of code just got handed over to me and I got baffled by macros in the header. I could not understand what they are for: #define WRAPPER_MACRO(symbol) symbol #define ANOTHER_SYMBOL ...
0
votes
0answers
3 views

Creating multiple child processes in C for one parent [migrated]

Everyone! So I've been working on code for my OS class, and in my project, I have to create a new child process for each file on the command line, and pipe information from the child to the parent. ...
0
votes
1answer
64 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
0answers
2 views

putting file-scope variables inside a struct? What is the benefit [migrated]

As a C developer I always used to place file-scope variables as their own variable. static char myChar; static char *myCharPtr; Now I've started people seeing to be placing these variables inside a ...
0
votes
1answer
77 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
174 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
219 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
0answers
67 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 ...
0
votes
1answer
152 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
89 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
84 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
169 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
222 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
204 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 ...
1
vote
0answers
90 views

Problem with Vi editor using PuTTy [closed]

For my computer science class for intro to c/c++ we are using the PuTTy client to work with Vi. During one of my assignments I was in the other room and apparently my cat jumped up on my laptop and ...
4
votes
3answers
299 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
134 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 ...
3
votes
3answers
183 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
2answers
216 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
333 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
74 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
105 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 ...
0
votes
2answers
197 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
146 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
192 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
112 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
6answers
492 views

Coming from high-level to C [closed]

I have a web background that grants me basic understanding over programming. Some older kids wouldn't even call that programming knowledge ("any moron can do PHP/Python/Ruby"), I guess, but let's not ...
1
vote
1answer
161 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
65 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
104 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
96 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
43 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, ...
2
votes
2answers
167 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 ...
0
votes
2answers
117 views

What are and how do (data-) types work?

What is a "variable"/data type? How does a compiler / interpreter handle types? My specific concern has to do with the different types in lower and higher level languages. For instance in Python, ...