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
1answer
31 views

Finding register parameters for system calls

By consulting various scattered tutorials and books, I've been able to learn that the 64-bit Linux "exit" system call is 60, and the status value is moved to edi. Similarly, "write" has call number 1, ...
-3
votes
0answers
27 views

Calculator console apps with C Language [on hold]

I want to write a program that perform a set of operation on string and calculates the results. Input: 5+3×(5×6)×8−5−+3+5×7+4÷8+6 Output: 758.5 This is the code that I could write..... #include ...
-5
votes
0answers
75 views

XML Stuctured C [on hold]

Has a Programming Language been developed, which structures C code within XML like tags? (Y/N) If not please mention a place where I should submit this idea. (Sorry that this is a slightly open ended ...
8
votes
1answer
111 views

What is the origin of the C Preprocessor?

The C preprocessor is attached to C, but it has a completely different syntax from the main language: syntactically significant whitespace (end of line terminates a statement, gap after the macro ...
4
votes
4answers
217 views

Interview question on accessing variable with pointers in c [on hold]

Once I had a question in interview, it goes something like this. int main() { int a = 10; int b = 20; int *p = &a; // can i access b or can i get my pointer p to point to b. } ...
4
votes
3answers
80 views

Unit Testing Module-Internal Functions

I'm writing a simple whitebox unit testing suite for a project I'm working on in C. The project is broken into modules (each has a .c file with an associated .h file), and all modules are compiled ...
-5
votes
0answers
46 views

Solving a problem involving probability [closed]

The problem I am given is the following: Write a program to discover the answer to this puzzle:"Let's say men and women are paid equally (from the same uniform distribution). If women date ...
-3
votes
0answers
107 views

Cons and Pros of ternary operator instead of if/else [closed]

I have some set of code in which same code is written by using two logics. which are as follows. 1. if (cart.getFacebookShare()) { return BigDecimal.TEN; }else{ return BigDecimal.ZERO; } ...
-8
votes
1answer
43 views

I want to make a quiz app using C in which it must give at last based upon answers? [closed]

Like there will be three questions and according to options swlected answer will be returned. e.g. Will you return free money ? a. y b. n and two more Based on option answer will be given that ...
-5
votes
1answer
76 views

Dangerous Dave game parameters live access [closed]

I have searched online for Dangerous Dave source code however I wasn't able to find any. So I wanted to know, is there any way I can access the score and other game parameters while playing the game. ...
-1
votes
1answer
44 views

(Multidimensional array in C) How to make my output in a vertical position rather than in horizontal when the size of the array is n[3][4] [closed]

I would like to have some help. I must find a way that the output must be: A B C 90 60 80 50 100 70 100 20 100 10 50 75 Because the previous output is: A 90 50 100 10 B 60 100 ...
26
votes
13answers
2k views

Help in understanding computer science, programming and abstraction [duplicate]

Until now, I always believed that you should learn programming languages that make you do low-level stuff (e.g. C) to understand what's really happening under the hood and how the computer really ...
12
votes
5answers
1k views

Is it bad to write object oriented C? [closed]

I always seem to write code in C that is mostly object oriented, so say I had a source file or something I would create a struct then pass the pointer to this struct to functions (methods) owned by ...
-2
votes
1answer
168 views

Could ANSI C standardized linkage syntax from early C wrong? [closed]

Recently I came up to something illogical, reading the latest ANSI C paper. It was talking about linkage but it never mentioned a way to declare internal identifiers inside block-scope (or at least in ...
0
votes
2answers
131 views

Efficient Repeating Alarm Clock in Low Level Language like C

I was thinking about it and I was curious as to how one would code an efficient repeating alarm clock in C? Would you set an alarm time and then offset the time with the ms time equivalent of a day ...
29
votes
5answers
5k views

If a number is too big does it spill over to the next memory location?

I've been reviewing C programming and there are just a couple things bothering me. Let's take this code for example: int myArray[5] = {1, 2, 2147483648, 4, 5}; int* ptr = myArray; int i; for(i=0; ...
7
votes
1answer
98 views

Unit Testing: Assembler code and different architectures

I am currently unit testing some C code and I am faced with a problem: Within the code there are called functions that contain inline assembler code for the SPARC 8 architecture. Since I am doing ...
8
votes
3answers
338 views

How useful is C's “true” sizing of variables?

One thing that always intuitively struck me as a positive feature of C (well, actually of its implementations like gcc, clang, ...) is the fact that it does not store any hidden information next to ...
-2
votes
1answer
93 views

Problem on recursion

void function(int x){ if(x<=0) return; function(x--); } This is a recursion function which is called with the value of x = 20. The Recursive call will take place in this way ...
1
vote
2answers
119 views

Declaration confusion in pointers [closed]

I was just confused about the following declaration in C: char **p[5] I understand the char *p[] as an array of character pointers, but this one is puzzling me. Based on the precedence of [] over ...
9
votes
4answers
220 views

Is there a standard way or standard alternative to packing a struct in c?

When programming in C I have found it invaluable to pack structs using GCCs __attribute__((__packed__)) attribute so I can easily convert a structured chunk of volatile memory to an array of bytes to ...
6
votes
5answers
325 views

What does it mean to declare a volatile variable?

Many low level programs use the volatile keyword for types for memory mapping and such, however I'm sort of confused as to what it REALLY does in the background. In other words, what does it mean ...
3
votes
1answer
101 views

How to communicate between cooperative tasks “first me, then you”?

I am in the final stages of development of a simple embedded system. The device performs PID coefficient estimation and then instantiates a PID controller with the estimated coefficients. The ...
5
votes
3answers
130 views

How to create “constructors” for structures in C

The problem I have this structure that I want to create a "constructor" for it. struct example { int x, y, z; /* various members */ struct another *another; /* pointer to another structure ...
33
votes
9answers
2k views

Doesn't “always initialize variables” lead to important bugs being hidden?

The C++ Core Guidelines have the rule ES.20: Always initialize an object. Avoid used-before-set errors and their associated undefined behavior. Avoid problems with comprehension of complex ...
10
votes
3answers
440 views

Is it bad to refer to access array elements via pointer arithmetic instead of the [] operator?

I've just started learning to program in C, and to improve my understanding of pointers and arrays, I tried to refer to the elements of an array without creating any pointer at all: for(k1 = 0; k1 ...
20
votes
2answers
2k views

Are header-only libraries more efficient?

Assumptions One of the advantages of header-only libraries for C++ is that they do not need to be compiled separately. In C and C++ inline makes sense only if the function is defined in a header ...
25
votes
10answers
5k views

Isn't the use of pointer variables a memory overhead?

In languages like C and C++, while using pointers to variables we need one more memory location to store that address. So isn't this a memory overhead? How is this compensated? Are pointers used in ...
2
votes
2answers
116 views

Difference in endianness between operating systems [closed]

There is an assembler that I am writing that is located within the file asm.c located in this repository. It uses the instruction set located in the specs file to produce an output binary. (The ...
1
vote
1answer
39 views

Efficiently determining many-to-many subset relation

I'm doing market basket analysis. I have a set of transactions. Every transaction is a set of items that were bought. I then have a set of itemsets (i.e. a set of items) that I want to determine the ...
-1
votes
1answer
62 views

What is the hash value of each member of the group? Before modding?

This isn't an actual code related question but it relates to C. We are given: Amy's club has grown and now includes the following members: Abel, Abigail, Abraham, Ada, Adam, Adrian, Adrienne, ...
1
vote
2answers
51 views

One C codebase as an standalone application as well as Fast-CGI and Apache module

I'm familiar with C, but haven't written any medium or large application in it. I have a requirement to built an application that can be run as a standalone console application as well as Fast-CGI and ...
-2
votes
1answer
240 views

Bresenham Vs Midpoint Circle drawing algorithm

Can somebody explain the difference between Bresenham and Midpoint Circle drawing algorithms? All I am able to understand is that in both algorithms we compute coordinates of an octant instead of ...
5
votes
1answer
122 views

Strategies to increasing the maintainability of assertions in code [closed]

Background I am writing a compiler for a custom language for a school project and it is going really well for me. If I where to start all over from scratch I would have done many software ...
3
votes
1answer
182 views

Are include guards necessary if headers only contain declarations?

Consider the following assumptions about C programming (some of which go too far, I confess): Putting any variable definitions in a header file is incorrect, because each translation unit creates ...
-1
votes
1answer
142 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 ...
-2
votes
1answer
155 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
353 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 ...
-1
votes
1answer
156 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 ...
52
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
51 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
141 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
116 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
321 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
0answers
34 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 ...
2
votes
1answer
82 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
127 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
364 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
113 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
131 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 ...