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

learn more… | top users | synonyms

0
votes
0answers
14 views

A callback for when data is received?

So, my understanding is that the Kernel could receive TCP at any time, and that generally a C program asks the Kernel synchronously/asynchronously if it has data available. Would it be possible for a ...
2
votes
1answer
88 views

What would be a reason not to embed JS in C?

I'm working on an opensource application that processes JSON in C, because I would like to make it easier for people to help me in the project and because JSON is so close to JS. I want to embed a JS ...
-4
votes
0answers
52 views

Where can I find a compiler [on hold]

and tried looking for a c compiler. I have tried GCC which is now GNU I think now, but did not seem to work is there any advise people can give to some just looking to start out thanks Hayden
0
votes
1answer
76 views

How do I avoid using regular expressions in this example?

I'm going to use ftw.h to iterate over two directorys and load up two separate structs with file information. Currently my idea is to load a singly-linked list with the absolute pathname, stat ...
-3
votes
0answers
25 views

How to compile Selenium on Debian Jessie, failing on ibus [on hold]

When I compile Selenium on Debian Jessie, it gives me this output. I have ibus lib installed. I think that I use different version. I am right, how can I solve it? If you need to provide any ...
3
votes
0answers
55 views

Assembly: push vs movl [migrated]

I have some C code that I compiled with gcc: int main() { int x = 1; printf("%d\n",x); return 0; } I've run it through gdb 7.9.1 and come up with this assembler code for main: ...
1
vote
2answers
52 views

What should JITed bytecode do exactly?

I'm working on a VM (and a scripting language for it) that I plan to implement JITing for. I'm only working on the "plumbing" of it now, but I don't want the JIT compiler to be an afterthought. ...
2
votes
1answer
95 views

Endianness at bit level

I am learning the union and struct and I wrote the code below. What I do not understand is why the output is different when I change from a little endian to a big endiann machine. My understanding is ...
-5
votes
0answers
33 views

I am learning c programming using codes represented on web please help [on hold]

I am making a bank type program. I am stuck in if else statement step. Pls help Codes are as follows: #include<stdio.h> #include<conio.h> int main() { char fName; char mName; char ...
0
votes
0answers
4 views

About BMP file. How can i write/change a pixel color? (in C) [migrated]

I'm trying to change a pixel from a picture (format bmp, 24 bits). I have this 3 structures: for file header: #pragma pack(2) typedef struct { unsigned short int typeID; unsigned int size; unsigned ...
-1
votes
0answers
39 views

Is there any way of doing if/while assignment in Visual Basic? [on hold]

For example, in C/C++, you can do the following: #include <iostream> #include <conio.h> int main() { char c; while ((c = getch()) == 'f') { std::cout ...
2
votes
1answer
139 views

What is the motivation for casting a pointer into a integer?

I'm doing some changes in the Linux kernel code and have noticed a pointer being cast into integer. Check out buf below (full code): snd_pcm_sframes_t snd_pcm_lib_read(struct snd_pcm_substream ...
2
votes
2answers
106 views

Why dynamic memory allocation functions in C returns void*?

Consider the prototypes of C's dynamic allocation functions malloc - void* malloc(size_t size); calloc - void* calloc(size_t n,size); realloc - void* realloc(void* ptr,size_t newsize); Now a ...
-5
votes
0answers
44 views

Making career in C Programming / Linux Embedded or Linux driver development [closed]

Before putting up my question I want to brief about my career background , I have been working in IT industry since 5 years in Unix ( HP-UX) Domain as system administration and have some knowledge of ...
23
votes
5answers
2k views

Should I initialize C structs via parameter, or by return value? [on hold]

The company I work at is initializing all of their data structures through an initialize function like so: //the structure typedef struct{ int a,b,c; } Foo; //the initialize function ...
1
vote
2answers
79 views

Multi-pattern matching

I have a given byte array in C and I need to match it against several byte arrays and return true if there is any match. I can make various memcmp's but I feel that it is very inefficient. Do you ...
0
votes
1answer
192 views

C code to object oriented [closed]

My research mentor provided me with some C++ code. Trouble is, it's basically C: it's in one big file, the header doesn't declare a class or even prototype functions, the filename and content of an ...
0
votes
0answers
59 views

Fast fixed-size (256 bit) integer modulo/division

What is the fastest way to divide two 256-bit integers? They are represented as an array of 26-bit words, each stored in 32-bit integers. I have access to a 64-bit type if that's useful. It seems ...
0
votes
0answers
22 views

C Programming - Insert value into singly linked list after specific node [migrated]

I have a program I have been sweating over and keep getting a segmentation fault on the function insertAfter. I was given the base code and asked to create serveral functions. I have gotten most of ...
-3
votes
0answers
79 views

Basic programming C Question [migrated]

Ok, so i'm trying to write a program that can check to see if a number is evenly divisible by 2, 3, 4 or 5. For example if the user enters 8, the output would be: “8 is divisible by 2” “8 is ...
0
votes
0answers
3 views

Initialize string array in C and count number of letters inside [migrated]

I found this example`int SizeofCharArray(char *phrase) { int size = 0; int value = phrase[size]; while(value != 0) { value = phrase[size]; size++; }; //printf("%i%s", ...
0
votes
2answers
166 views

In C, how are functions accessible if they're not inline or called by #include? [closed]

I'm looking at code that somehow calls a library but I don't see it calling any of the library's headers at any point. I've done searches within the code and I don't see anywhere the functions, ...
2
votes
1answer
136 views

Does applying a prefix to member variables make sense in C? [closed]

//C code struct Foo{ int m_nVar; } struct Foo f; f.m_nVar = 0; Despite the fact that many consider Hungarian Notation an anti-pattern, I am working in a code base that enforces it. 90% ...
-1
votes
2answers
131 views

How does the post increment operator work in GNU C? [closed]

While the run the below program in Turbo C compiler, I am getting the expected output, however, when I run the same program it using "gcc" compiler in linux, it is giving an unexpected output! int ...
1
vote
3answers
190 views

What does the “t” in int32_t signify?

In C, what meaning, if any does the t at the end of integer types like uint8_t and int32_t have? Where did it originate? Why wasn't the type just called int32?
12
votes
1answer
343 views

Why using sizeof of type to calculate the number of elements in an array is considered inferior to using sizeof of an element?

I'm reading "King K.N's C programming" and I'm reading the following statement: We discussed using the expression sizeof(a)/sizeof(a[0]) to calculate the number of elements in an array. The ...
1
vote
3answers
112 views

How much can you detect undefined behaviour using testing [closed]

I hope this question fits this site. You may know you can't detect undefined behaviour in C using compilers - and some tools (static analysis) can help you detect it. My question is more empirical - I ...
1
vote
1answer
209 views

Inserting C++ code into C [closed]

What I need to do before inserting C++ code into C, and how to do it? Are there any examples to show me how this can be done. I have a good knowledge of C, but never mixed those two. Thanks for the ...
0
votes
1answer
94 views

floating-point number stored in float variable has other value [duplicate]

I'm reading a book about C programming By "King.K.N" and I'm reading the following statement: If we store 0.1 in a float variable, we may later find that the variable has a value such as ...
3
votes
1answer
284 views

How do C/C++ programs get ported to different platforms? [closed]

Java applications can run on different platforms because they always run on top of a Virtual Machine specifically developed for each platform. So, there's no native installation, you just drop the ...
0
votes
2answers
101 views

What's the simplest way to deal with events in C in this situation?

I'm writing a text-based game, in C. I want the game to handle NPCs movement and actions in the background, while the user is making his moves. I'd also use time-based events to tell the user when ...
9
votes
5answers
2k views

Simple and clean way of comparing three numbers

I've got some code that has a sequence of ifs that work, but just feel messy. Basically, I want to choose the largest of three integers and set a status flag to say which was chosen. My current code ...
1
vote
1answer
68 views

Best practices for tracking multiple pieces of data in a program

I have a project in C (don't ask why but it needs to be in C), where I need to track multiple pieces of data and commands for different modules. Some actions that the program will take depend on the ...
2
votes
1answer
69 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 ...
0
votes
2answers
78 views

Multiple threads making call to precompiled library

I have been asked this question in an interview and I thought to take advice from you guys. Say I have a pre-compiled library which references to some function say "strtok". There is no source code ...
2
votes
2answers
97 views

What is the point of designing Lua C APIs?

I am a newbie of Lua. After studying some Lua C APIs examples, I am a little confused. I can see the Lua C API is used for processing Lua scripts: ...... lua_State *L = luaL_newstate(); ...
1
vote
2answers
106 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 ...
16
votes
2answers
335 views

Has variable width types been replaced by fixed types in modern C?

I came across an interesting point today in a review over on Code Review. @Veedrac recommened in this answer that variable size types (e.g. int and long) be replaced with fixed size types like ...
3
votes
3answers
117 views

How to maintain modularity in C?

I am writing C code with multiple modules like LCD display, flash memory, and GSM module etc. The project consists of thousands of lines of code, in different files. The behavior of the system can be ...
6
votes
2answers
1k views

What is the difference between function() and function(void)?

I have heard that it is a good practice to write functions that do not receive anything as a parameter like this: int func(void); But I hear that the right way to express that is like this: int ...
-1
votes
2answers
43 views

If I #include a file, do I need to have a valid path to any headers #included in the included file [closed]

For example, if I have created a library, libcommon, which uses some other custom, but widely used library in a specific field (some_other), like this: libcommon.h #ifndef LIBCOMMON_H #define ...
26
votes
10answers
6k views

What is the “type” of data that pointers hold in the C language?

I know that pointers hold addresses. I know that pointers' types are "generally" known based on the "type" of data they point to. But, pointers are still variables and the addresses they hold must ...
1
vote
0answers
333 views

Why C doesn't have better notation for pointers? [duplicate]

The * symbol is used for three different purposes multiplication Pointer declaration Pointer dereferencing. Why designers of C kept this notation? In other words, wouldn't it be nice if there ...
2
votes
1answer
127 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 ...
9
votes
8answers
1k views

What stops C from being compiled/interpreted/JIT'ed?

Java is often praised for its amazing portability, which I presume is because of the JVM. My question is what stops C from being being compiled/interpreted/JIT'ed.., if so, C can also be write once ...
35
votes
6answers
4k views

How to think as a C programmer after biased with OOP language? [closed]

Previously, I've only used Object Oriented Programming languages (C++, Ruby, Python, PHP), and am now learning C. I'm finding it difficult to figure out the proper way to do things in a language with ...
5
votes
1answer
257 views

Kth selection routine - Floyd Algorithm 489

I have recently come across a promising Kth selection routine that reportedly outperforms quickselect the Floyd, Rivest Select routine. This Wikipedia article provides a pseudocode version which I ...
0
votes
0answers
29 views

Synchronizing content between web-based app and game server

I have a MUD server, written in C, that I'm trying to move from file-based storage to MongoDB. Eventually, I'd like to offload administration of game content and settings to a web console, written in ...
-2
votes
1answer
90 views

Copying desired bits from variables [closed]

What's the best way to copy desired bits from char, int or any other variables? I want to see all possible and the most efficient techniques for this purpose. I have for example 16bit variable 0000 ...
5
votes
2answers
110 views

What is a reasonable level of detail for a style guide? [closed]

We are developing embedded software for an automotive product in ANSI-C in a large team. Yesterday, in our regular code review, we had a general discussion about the style of our code. We have a ...