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

learn more… | top users | synonyms

3
votes
5answers
2k views

API design pitfalls in C

What are some flaws that drive you nuts in C APIs (including standard libraries, third party libraries, and headers inside of a project) ? The goal is to identify API design pitfalls in C, so people ...
13
votes
2answers
818 views

How important it is to fix memory leaks?

I found by Valgring that some GTK+ programs leaks memory. How important it is to fix those leaks? I mean, often those programs works very well but on the other hand, one can never be sure if one wants ...
89
votes
10answers
10k views

Should I stop using the term C/C++?

I understand C and C++ are different languages but when I was learning C++ I was always told that C is a subset of C++ or C++ is C with classes. And that was quite true until the appearance of C++x0, ...
-1
votes
3answers
134 views

How should I proceed to make a program that, when given three sides of the triangle in an array, will determine if they can make a valid triangle?

Given three sides of a triangle. I have to determine by writing a program using C language whether I can make a valid triangle or not using these three sides of the triangle. So how should I proceed ? ...
3
votes
4answers
168 views

Source control workflow for managing a software platform

I'm in charge of a software platform, written in C, that is used to provide a variety of projects to clients. I am trying to improve the workflow for people using this platform, and looking at ...
5
votes
6answers
1k views

Why is C++ backward compatibility important / necessary? [closed]

As far as I understand it is a wide-spread opinion within the C++ community that certain features of C++ (including some features inherited directly from C), while still usable in themselves, do not ...
-4
votes
0answers
44 views

its just a simple execution problem in my beginners c program [on hold]

Can some one run the c below code and tell me why it runs but the first entry is allowed but instead of allowing the second entry goes straight to issue a comment that the executable file for this ...
4
votes
2answers
117 views

How to abstract from a display?

I'm building an embedded text editor consisting of a keyboard, an LCD display and a PIC32 microcontroller, to be programmed in C. The application should look, for example, like the GNU nano editor. ...
6
votes
4answers
370 views

What are the key differences between low-level C development and higher level OOP development? [duplicate]

I have been using high-level OOP language (like C# and/or Java) for quite some time. I know patterns like the gang of four, can read and write code reasonably well and am considered a senior by his ...
-4
votes
0answers
51 views

Where can I learn enough C for systems programming? [closed]

I have some experience with C so usual things that are given in books/courses are not enough for me. I'd like to know where do I get C experience needed for example to complete the MIT JOS system. Or ...
2
votes
1answer
89 views

Using own ArrayList in general purpose C libraries, but allowing a different implementation

I've written a couple of libraries since beginning to use C again last year. One thing that still needs addressing in both of these is the correct use of array-based lists - hereafter, ArrayLists. At ...
-5
votes
0answers
40 views

Help understanding pointers [closed]

i have some trouble understanding pointers. we have this c code: int var = 5; printf(var); Since the output will be '5', does that mean that the variable var is a pointer, since it is able to ...
0
votes
2answers
37 views

Make: Greedy search for sources vs. a more selective approach… or a hybrid?

I rewrote my makefile a while back to get the benefit of greedily searching for and compiling all sources under some root folder. I'm very happy with it except for the fact that the source libraries I ...
-5
votes
0answers
59 views

node js vs. C differences [closed]

I do not want to know "which one's better" I'm simply looking for a new language to learn. If I learn C I get all the great benefits of being completely in control and access to unbeatable native ...
2
votes
1answer
35 views

Benefit of non-volatile access to volatile objects being undefined?

This is a question about ISO C, which contains this sentence: If an attempt is made to refer to an object defined with a volatile-qualified type through use of an lvalue with ...
-1
votes
0answers
54 views

weird malloc behavior in C [migrated]

I have the following ANSI C code: #include <stdio.h> #include <stdlib.h> #include <string.h> int main(void) { char *buffer = 0; int length = 0; FILE *f = ...
-1
votes
3answers
288 views

Exercise in 1.6 C by Kernighan and Ritchie [closed]

I'm using this book by Kernighan and Ritchie, on the chapter about character input and output and file copying, I'm totally lost as to what this chapter is talking about. This question may seem too ...
-1
votes
0answers
17 views

SQLBindParameter and SQLExecute returns SQL_NEED_DATA [migrated]

I'm working on a C application that interacts with a mssql database running on Windows 2008 R2. I'm able to connect to the database and run specific queries, but when i use SQLBindParameter things ...
-4
votes
0answers
29 views

Attempting to create multiple if-else conditions [migrated]

I am writing a program that involves checking the validity of a date. I have set the conditions for the months which have 31 days in them, and I have set the conditions for the months which have 30 ...
1
vote
3answers
154 views

Are file-scope `static` variables in C as bad as `extern` global variables?

In C, you'd often/sometimes (as a matter of style) use a file-scope static variable where you'd use a private class member variable in C++. When scaling to multithreaded programs, simply adding ...
2
votes
1answer
1k views

register variable in C and C++

I know the concept of register variable and it's use cases but there are few questions in my mind based on what I have tried. I cannot access the address of a register variable in C though I can do ...
0
votes
2answers
71 views

How does the LLVM compiler treat arithmetic operations in parentheses?

When it sees the parentheses, does it have the machine do the operations in the parentheses first, or does it distribute out the parentheses? Like, if I have the following line of code: int i = 2 * ...
-3
votes
2answers
140 views

Best x86 processor(computer) to learn computer architecture and assembly [closed]

I'm planning to build a computer as a hobby from scratch, with the least basic hardware possible in functionality so I can learn the basics of computer architecture and assembly language. I already ...
0
votes
2answers
200 views

Mixing OOP and Non-OOP

I'm working on a command line interface text based game. I'm writing it in C but there are various ways in which I could refactor the code by using Objective-C: using NSDictionary to allow me to ...
0
votes
2answers
73 views

C: How does struct node * next work? [closed]

In C, for creating linked list we write: struct Node{ int data; struct Node* next; }; So, my understanding is "struct Node* next" is a pointer variable of "Node" datatype. But how does it point to ...
-2
votes
1answer
80 views

When to use typedef in C programs? [closed]

I'm learning C programming language... I discovered recently the typedefkeyword... When is the right time to use it in a C program? And this is an example: typedef struct Books { char ...
3
votes
2answers
195 views

Methods of “Code Softening” (Opposite of “Hardening”) for C & C++ [closed]

Some developers work on code hardening. (protecting against errors, you can build with a stack protector for example). However, if you're trying to redo a strange someone else reports, or find ...
1
vote
2answers
119 views

Will issues arise packaging libc and pthread with your C apps?

The issue I hit, is that I am packaging shared libraries with my code in order to load GNUTLS, except for libc, because I figured any system will have it. Most of them don't have the required 2.14 for ...
6
votes
5answers
795 views

Why do we have to tell printf() the type of data in C?

Let's consider this C code: #include <stdio.h> main() { int x=5; printf("x is "); printf("%d",5); } In this, when we wrote int x=5; we told the computer that x is an integer. The ...
8
votes
6answers
4k views

Can you learn functional programming in C? [closed]

As a result of the comment discussion here, I wonder whether you can learn Functional Programming in C?
1
vote
3answers
13k views

Char and unsigned char [closed]

Where is unsigned char used in C ( please tell about some real-world examples )? Why would we need both char and unsigned char? Char ranges from -127 to 128 ( 8-bit integer ) Unsigned Char ranges ...
8
votes
4answers
3k views

When is the register keyword actually useful in C?

I am confused about the use of register keyword in C. It is generally told that its use isn't needed like in this question on stackoverflow. Is this keyword totally redundant in C due to modern ...
16
votes
3answers
616 views

Why are C string literals read-only?

What advantage(s) of string literals being read-only justify(-ies/-ied) the: Yet another way to shoot yourself in the foot char *foo = "bar"; foo[0] = 'd'; /* SEGFAULT */ Inability to elegantly ...
6
votes
0answers
1k views

How is memory managed for non-declared entities in the C language? [migrated]

For example: In the following code, how and where is the number '10' used for the comparison stored? #include<stdio.h> #include<conio.h> int main() { int x = 5; if (x > 10) ...
5
votes
2answers
615 views

On concatenating adjacent string literals

C and C++ compiles adjacent string literals as a single string literal. For example this: "Some text..." "and more text" is equivalent to: "Some text...and more text" In other C-family languages ...
0
votes
2answers
300 views

How are complex programs made? [duplicate]

I know a few languages, and can program in them. How do multiple languages blend together in a single program? For ex. https://github.com/facebook/watchman. This uses C, PHP, Python, Javascript, etc. ...
0
votes
2answers
155 views

Does printf in C99 automatically round numbers for me? [closed]

Does printf in C99 automatically round numbers for me? I wrote a program as shown below and I am getting unexpected output. #include <stdio.h> #include <math.h> int main(void) { ...
56
votes
14answers
7k views

Are data type declarators like “int” and “char” stored in RAM when a C program executes?

When a C program is running, the data is stored on the heap or the stack. The values are stored in RAM addresses. But what about the type indicators (e.g., int or char)? Are they also stored? ...
22
votes
6answers
100k 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 ...
0
votes
6answers
1k views

Why languages that compile to C/C++ generate unreadable, cryptic code? [closed]

I'm willing to compile certain language to C or C++ for some speedups. My idea was, though, to generate readable code and use structures such std::vector and similar wherever I can, expecting CLANG to ...
21
votes
6answers
2k views

Why use an opaque “handle” that requires casting in a public API rather than a typesafe struct pointer?

I'm evaluating a library whose public API currently looks like this: libengine.h /* Handle, used for all APIs */ typedef size_t enh; /* Create new engine instance; result returned in handle */ ...
3
votes
6answers
591 views

Design decisions while porting a non object-oriented C program to Java

Background: My boss made a comment on porting a C program that acts as some a simulator that communicates with a remote process through sockets to Java. He didn't assign it to me, or to anyone for ...
1
vote
4answers
128 views

When is an object passed to a function?

Trying to clearly state the semantics of a function call. In calling a function, are the arguments passed to the function the ones the calling code initially gives or the ones the function ...
0
votes
2answers
120 views

why use postfix /prefix expression instead of infix?

I understand how to convert infix to postfix/prefix but I do not understand why postfix or prefix expression are used in computer system? What is the advantage of postfix prefix over infix ...
1
vote
3answers
443 views

C: “this” vs “<instance name>”

I'm using C in a minimal, efficient OOP style to build a game engine. A problem I've begun to face as the engine code settles is my (erstwhile) choice to use this. For example, I have: void ...
1
vote
1answer
49 views

What is the most efficient way to discover devices on a network?

I've been programming a C web server from scratch as an interface for controlling ESP8266 WiFi modules that I plan to use to control appliances & lighting with relays. In an attempt to make a ...
7
votes
3answers
1k views

Is macros support in a programming language considered harmful?

The first abuse that comes to my mind in C is: #define if while But at the same time it is extremely handy and powerful when used correctly. Something similar happens with Common Lisp macros. ...
-2
votes
1answer
165 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 ...
3
votes
3answers
178 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 ...
63
votes
4answers
35k views

How is a Java reference different from a C pointer?

C has pointers and Java has what is called references. They have some things in common in the sense that they all point to something. I know that pointers in C store the addresses they point to. Do ...