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

What comes between C code and assembly? How should I design this “middle” piece?

I've written a virtual machine in C that can run a bytecode program loaded from a data file. Initially, I was testing this virtual machine by writing out the bytecodes myself using excel but I've ...
0
votes
0answers
60 views

How can I learn to write device drivers for linux? [on hold]

I've been searching around for good reading material, but unfortunately haven't found anything that seems to cover what I'm looking for. I've never developed drivers for linux before, so I'm looking ...
-3
votes
0answers
27 views

Using log4cxx API in C code [on hold]

I need some advices on how to use log4cxx in my C code. It looks so complicated to me, considering that I only know C, not C++. What are things I need to learn to do that log4cxx implementation in my ...
1
vote
3answers
103 views

How much can you detect undefined behaviour using testing [on hold]

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

Inserting C++ code into C [on hold]

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
87 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
252 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
90 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 ...
-1
votes
0answers
23 views

Linux header files for Win32 typedefs like BOOL, LONG, and WCHAR [migrated]

I'd like to compile this clone of xcopy as a linux binary. I commented out all the win32 include files, and now it complains about things like WCHAR, and LONG. These are simple typedefs. Is there a ...
-2
votes
0answers
6 views

micro SD -TFT communication Micro C compiler AVR [migrated]

I need help, I want to write picture.bmp from Micro SD to Adafruit TFT, but it wont work, here is the code, I m using ATMEGA128A, AVR microcontroller and Mikroc compiler. #include"ILI9340.h" ...
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 ...
-2
votes
0answers
7 views

C programming code error [migrated]

So the program is still incomplete, i cant go any further cause there is an error right after the first input, i tried using visual studio 2010 and 2015, both with the same problem: unhandled ...
0
votes
0answers
19 views

#define as unsigned char [migrated]

I would like to know how can I tell to compiler that a #define is an unsigned char. if #define 1 byte do this: #define AACEESS_PSS 0x80 #define ACCESS_PSS ((unsigned char)0x80) but if ...
1
vote
1answer
61 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
68 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
75 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
90 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
93 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
318 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 ...
0
votes
0answers
39 views

Why we always have to use fgetc command in C programming instead of fscanf which do the same thing but prints strange results? [migrated]

In C programming whenever I use fgetc(file) to read all the chars until the end of the file it works. But when I use the similar fscanf(file,"%c") function it doesn't works. For example: File ...
3
votes
3answers
109 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
42 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
329 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 ...
-4
votes
0answers
14 views

Not getting expected value when running a program [migrated]

int a=10; float b; printf("the no\n"); b=((10-1)/12)*50; printf("b value is %f",b); return 0; But when I calculate the b value in scientific calc we get b=40. And my question is why it shows b=0 ...
0
votes
0answers
47 views

Matrix column dimension containing '>' in C [migrated]

I found a small C function that given a matrix, it removes the line 0 and the column 'i' and then put it in another matrix, everything in order to calculate the determinant of the simplified matrix , ...
2
votes
1answer
121 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 ...
8
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
239 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
26 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
79 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
109 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 ...
2
votes
2answers
110 views

What are the benefits of a device driver when I can access the I/O registers directly?

I was interested in what modern, C-based, Linux device driver development looked like, and so I took a good gander at this excellent article. I didn't read every single line, but perused the majority ...
2
votes
2answers
83 views

Compiling and deploying a C program to an MCU running an RTOS

Please note: Even though I'm specifically talking about an RTOS called Embox here, and even though I'm talking about AVR/ARm, I think this question can be answered by anybody whose ever done a fair ...
2
votes
1answer
64 views

Compiling and deploying RTOS to an MCU

Please note: Even though I'm specifically talking about an RTOS called Embox here, and even though I'm talking about AVR/ARm, I think this question can be answered by anybody whose ever done a fair ...
3
votes
2answers
163 views

Benefits of RTOS vs Bare Metal for MCU Programming?

Please note: This question specifically mentions two RTOSes but is more generic and can probably be answered by anybody who has written C code for embedded RTOSes before, and had their software run ...
0
votes
0answers
56 views

GMP Core Dump while using mpz_clear in C

I'm working on a prime factorization program written in C using the GMP library through cygwin. The algorithm that I have now works fine, but has memory leaks from not using the mpz_clear function on ...
49
votes
8answers
6k views

Why does C provide language 'bindings' where C++ falls short?

I recently was wondering when to use C over C++, and vice versa? Fortunately someone already beat me to it and although it took a while, I was able to digest all the answers and comments to that ...
0
votes
0answers
74 views

Best way to signal all child processes to terminate using C

I have been assigned the task of designing a simple web server using C in my UNIX & C class. The webserver listens and forks when a successful connection is made so that multiple clients may be ...
2
votes
0answers
163 views

Have any C compilers ever *defined* `unsigned short x=-3; x*=x;` to yield anything other than 9

In a C implementation where int can hold all values of type unsigned short, standard integer promotion rules dictate that given the code: unsigned short x=(USHORT_MAX+1)-3; // Or just -3 x*=x; a ...
-2
votes
1answer
123 views

Question about switch-case statement [closed]

What happens, and does code work properly if we write switch-case structure like this, why its not good to write code like this? I'm porting some firmware and have switch-case statement interrupted ...
1
vote
1answer
84 views

Equivalent translation of Asynchronous behaviour in C

As a follow-up to my other question, if one were to build a general-purpose translator from a language that has support (be it with an external library or otherwise) for asynchronous behaviour to a ...
-3
votes
1answer
79 views

Executable File Size Difference Between Python and C [closed]

Does using lower level programming languages have benefit of generating lesser file size when creating an executable, in contrast to using higher level languages for the same algorithm?
3
votes
1answer
178 views

Implementation of Asynchronous function call in C

I took it upon myself recently to work towards making a general-purpose Translator to automatically translate js programs into C, but I got stuck when thinking of asynchronous behaviour. Using ANSI / ...
6
votes
8answers
741 views

Structuring Procedural vs OO code

I have spent the vast majority of my programming career using Java and very OO based C++. I am really interested in learning to think more procedurally, so I have been starting to do some practice ...
-2
votes
1answer
66 views

how integer type can handle text stream (getchar()) in C? [closed]

While going through C programming by Ritchie and kernighan, I came across the following code. #include<stdio.h> int main() { int t; t = getchar(); while ((t=getchar()) != EOF) { ...
2
votes
2answers
261 views

How does printf write to stdout?

I've been looking for an answer to this for a couple days, and all of the results I've come up with are about how printf accepts an arbitrary number of arguments. How does printf write to stdout? ...
-1
votes
2answers
100 views

In C is it possible to change http requests to https [closed]

Long story short I've got this package that currently has a security risk where credentials are sent over http and I need to convert them to https but I currently lack the knowledge to do so. Could ...