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

learn more… | top users | synonyms

-2
votes
1answer
155 views

How did the gets function ever make into the standard? [closed]

We all know the dangers of gets. It is also on the way out in C11. That makes me wonder: how did it ever get into the standard to begin with? Weren't the problems with it obvious at the time of ...
-1
votes
1answer
171 views

Why '-5<(unsigned)5' is false? [duplicate]

In c programming why I am getting 0 zero for this? Why -5<(unsigned)5 is false? main(){ printf("%d",-5<(unsigned)5); getch(); }
0
votes
2answers
405 views

Write C line by line

Is there any conceptual limitation that would make impossible to create a C program line by line as in 'Mathematica notebooks'[1]? [1] One key aspect of Mathematica is that you can create your code ...
0
votes
1answer
251 views

Is C programming language low level or high level? [duplicate]

What do you think, is C programming language low or high level? There are some information, in one is said that C is low level, and another C is high level? When I read book of Dennis Ritchie and ...
53
votes
7answers
4k views

Should one check for every little error in C? [duplicate]

As a good programmer one should write robust codes that will handle every single outcome of his program. However, almost all functions from the C library will return 0 or -1 or NULL when there's an ...
0
votes
1answer
52 views

Overwriting a C system after exec? [closed]

So I used wrap to override the malloc call in my program, I didn't think that if I exec'd another it would work, and it didn't. I figure this is because it wasn't linked with my program. How could I ...
0
votes
1answer
158 views

C automatic variables [closed]

I'm designing 2 functions, I'm trying to be sure I doing correctly. The idea is that in the first function , a struct pointer is created and passed to a function that might or might not fill the said ...
2
votes
1answer
248 views

Memory/cache performance in working with arrays in C

I've been toying with some array examples in C. I want to understand more about memory concepts, alignment, and cache. Especially on large arrays on heap. Sometimes I work on large images (extremely ...
2
votes
3answers
346 views

Why do most language's definition of substring allow substring(“abc”, 3) => “”

I've seen most languages have it be the case for their substring method that using the length of a given string in the method as the start index will give you an empty string. It is most definitely ...
0
votes
1answer
57 views

Best way to update driver data from userspace

I have a userspace application which interacts with a kernel-space driver in a Linux environment. The driver, in this case, is an LED driver. In typical *nix fashion, the driver exposes a file in /sys/...
2
votes
1answer
120 views

Questions about compiler/interpreter design [closed]

I am implementing a programming language, for fun, in C. I have most of the parsing code done and also the AST ready. I once did write a runtime for this language some time ago, but I had some trouble ...
3
votes
2answers
190 views

What's the REAL benefit of using CDECL? (more specifically pushing instead of reg-ing)

So, I'm learning assembly, and I've come to know the ABIs and i got some basics tests working using the cdecl calling convention to use the c's stdlib under nasm. But I've seen other Calling ...
2
votes
4answers
416 views

When was block scope for variables introduced to C, and why is it still frowned upon?

In light of the recent OBJ_obj2txt vulnerability in LibreSSL (which was found during the OpenSMTPD audit, and does not affect OpenSSL), it came to my attention that the memory leak issue likely ...
5
votes
1answer
167 views

How can I best test a multithreaded C producer-consumer program? [closed]

How does one best write tests for a multi-threaded producer-consumer C program? I know GDB can be used to debug threads, but I believe GDB also stops the thread currently being debugged while other ...
3
votes
0answers
152 views

Is it okay to write C code that must be compiled with -fno-strict-aliasing? [closed]

Some major C projects violate the strict aliasing rules in the C standard and must be compiled with -fno-strict-aliasing. These include Python, OCaml and the Linux kernel. Obviously this is not ...
1
vote
1answer
185 views

Data structure to use for time-optimized line-vs-grid check?

I am asking here because I feel that this question can be filed under the "algorithm and data structure concepts" category. Background: I have been recently assigned the task to design and develop a ...
-3
votes
1answer
178 views

grouping variables into a system in C? [closed]

Within C, say I have a number of variables, floats, integers etc, is there a way that I can group them all into one object, lets call it a system, and then create N copies of such an object. Further, ...
-3
votes
2answers
254 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? [closed]

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 ? ...
134
votes
11answers
20k 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, ...
0
votes
2answers
42 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 ...
2
votes
1answer
157 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
6answers
131 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 non-volatile-...
8
votes
4answers
616 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 ...
0
votes
2answers
104 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
441 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 ...
1
vote
1answer
244 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
2k 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 ...
3
votes
2answers
288 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
votes
2answers
347 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. ...
1
vote
2answers
150 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 ...
5
votes
7answers
710 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 ...
0
votes
2answers
887 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 expression?...
1
vote
4answers
139 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 receives?...
24
votes
7answers
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 */ ...
20
votes
3answers
2k 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 ...
2
votes
3answers
2k 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 ...
1
vote
1answer
189 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 user-...
4
votes
5answers
2k views

Checking array size in C/C++ to avoid segmentation faults

So it's well known that C does not have any array bounds checking when accessing memory. Nowadays, if you call myArray[7] when you initialised it as int myArray[3], your program will get a segfault ...
5
votes
2answers
131 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. ...
1
vote
3answers
476 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 ...
0
votes
3answers
97 views

Proper way to interpret this dereference operation?

I've seen this example in a text book and am a little confused how to interpret the operator precedence rules. Given this struct: typedef struct { char *data; size_t start, end; } ...
62
votes
14answers
9k 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? ...
-2
votes
1answer
88 views

What's an effective threading structure for NIO and server performance in C/C++? [closed]

I run into this issue where if I do a read to check for data too often, my CPU skyrockets, and if I don't check often enough, it's slow for client performance. What's an effective way to deal with ...
6
votes
4answers
390 views

When did Undefined Behavior in C jump the causality barrier

Some hyper-modern C compilers will infer that if a program will invoke Undefined Behavior when given certain inputs, such inputs will never be received. Consequently, any code which would be ...
2
votes
6answers
882 views

Replacing C with JavaScript as an introductory programming language [closed]

I am a new teacher at polytechnic where we teach web development and basic software programming. For years, the institution where I teach have taught C as their introductory programming language to ...
0
votes
0answers
72 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 ...
1
vote
1answer
240 views

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

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 ...
1
vote
2answers
88 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
223 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 endian machine. My understanding is ...
3
votes
1answer
320 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 *...