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

Inserting C++ code into C

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 ...
-6
votes
0answers
36 views

condition statements problem in c [on hold]

#include<stdio.h> #include<conio.h> main(){ char letter[2]; printf("Please Enter A Letter: "); scanf("%s",letter); if (letter=="a"||"b") { printf("That's an a ...
0
votes
1answer
83 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 ...
9
votes
6answers
913 views

I believe I have mixed C and C++ code when I shouldn't have; Is this a problem and how to rectify?

Background/Scenario I started writing a CLI application purely in C (my first proper C or C++ program that wasn't "Hello World" or a variation thereof). Around midway through I was working with ...
3
votes
1answer
222 views

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

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
83 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 ...
44
votes
5answers
10k views

Why are there no package management systems for C and C++? [closed]

There are some programming languages for which exist a package management system: CTAN for TeX CPAN for Perl Pip & Eggs for Python Maven for Java cabal for Haskell Gems for Ruby Is there any ...
16
votes
2answers
309 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 ...
-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 ...
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
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" ...
-4
votes
0answers
38 views

How the decision for the division type between integers and real numbers is been made in C? [closed]

If I divide 8 by 3 the result will be 2. But if I divide 8 by 3.0, or divide 8.0 by 3, the result will be of type double. How this decision is been made ?
-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 ...
5
votes
4answers
2k views

What do other languages offer when it comes to infrastructure technology that could indicate its advantage over C in the future?

I have been going through interview questions and I saw one which made me stop and think for a while. It starts with a quote and asks about your interpretation and whether you agree or not. "For ...
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 ...
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 ...
7
votes
1answer
1k views

“Read” a file without using a file pointer

I was asked this question in an interview. I'm somehow supposed to "read" a file into my C program as input without using a file pointer (including "f" functions, e.g. fgets, fscanf etc.). I'm also ...
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 ...
1
vote
2answers
92 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 ...
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 ...
2
votes
1answer
67 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
69 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 ...
1
vote
2answers
88 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(); ...
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 ...
5
votes
1answer
230 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 ...
2
votes
2answers
523 views

Is there a better way to organize my module tests that avoids an explosion of new source files?

I've got a neat (so I thought) way of having each of my modules produce a unit-test executable if compiled with the -DTESTMODULE flag. This flag guards a main() function that can access all static ...
2
votes
3answers
104 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 ...
0
votes
2answers
342 views

How small is the footprint of a small C compiler?

This week I could optimize using a reduced C library that allowed a drastic shrinkage in code size - from about 60 K to about 6 K and then we could load the code in the 8 K on-chip memory of an FPGA ...
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 ...
-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 ...
15
votes
2answers
4k views

Why does C use the asterisk for pointers?

I'm just now learning about C. I find it odd that the creators chose the asterisk (*) as the symbol for pointers rather than a symbol that actually looks like a pointer (->). Considering how ...
-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 , ...
1
vote
1answer
508 views

Help me construct a list of best approaches for new C and C++ developers [closed]

Not specific code writing practices. Please also include reasoning. My start: use GCC or Clang gcc because it is unchallenged in the amount of static checking it can do (both against standards ...
2
votes
1answer
119 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 ...
4
votes
2answers
276 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: ...
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 ...
-2
votes
0answers
13 views

For a given n,k find the sum [migrated]

For given n,k find the sum 1^k+2^k+....+n^k: I compiled this: #include<stdio.h> main() { int n,k,i,j=1,t,s=0; printf("enter n,k"); scanf("%d%d",&n,&k); ...
7
votes
4answers
1k views

The need for Explicit Type Conversion in C#

Consider the following code: DerivedClass drbObj = (DerivedClass)obj; Here obj is of type Object and this is reasonable since Object is the base type of every Class in C#. Here, since the type of ...
0
votes
0answers
25 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
72 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 ...
4
votes
4answers
3k views

What is important when optimising for the CPU cache (in C)?

Reading these two questions, I see that understanding CPU caching behaviour can be important when dealing with large amounts of data in memory. I would like to understand the way the caching works to ...
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 ...
9
votes
6answers
4k views

Can you learn functional programming in C?

As a result of the comment discussion here, I wonder whether you can learn Functional Programming in C?
17
votes
5answers
86k views

Is initializing a char[] with a string literal bad practice?

I was reading a thread titled "strlen vs sizeof" on CodeGuru, and one of the replies states that "it's anyways [sic] bad practice to initialie [sic] a char array with a string literal." Is this ...
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
2answers
106 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 ...
6
votes
8answers
736 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
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 ...