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

learn more… | top users | synonyms

-1
votes
0answers
63 views

What does “hardcore C programming” really mean? [on hold]

I've seen the term "Hardcore C programmer/programming" used by some programmers specialized in C. Searching online didn't yield any definitions what this adjective really means and how the term varies ...
1
vote
2answers
86 views

Given a number X, how do I find from an array of numbers, a unique combination that adds up to X and has the lowest sum of squares?

Given the number 15 and the array [1, 2, 3, 4, 5, 6] Possible combinations (sum=15) would be: [1, 2, 3, 4, 5] [2, 3, 4, 6] [1, 3, 5, 6] [4, 5, 6] Their respective sum of squares would be: 55, 65, 71 ...
0
votes
2answers
114 views

Infinite while loop CPU usage

I'm coding an script in C, which is going to check constantly an array of events, the idea is to check if the Date and time of certain event is equal to de current time and trigger something, i'm ...
-3
votes
0answers
34 views

Output of a program [migrated]

{ int a; a=4; cout<<a++<<++a; } The output of the above C++ program is 56 but why it is not 46 As a++ first print the value then increment a.
-2
votes
2answers
117 views

Returning void from a function specified to return int [on hold]

int count_to_ten ( int count ) { /* we only keep counting if we have a value less than ten*/ if ( count < 10 ) { printf("%d",count); count_to_ten( count + 1 ); } return; } int ...
-2
votes
0answers
139 views

How to call a function with argc & argv? [migrated]

I'm currently trying to create a GUI for an existing command line program using QT, as a learning exercise. The original code was written in c, and I have included the c wrapper for the c++ bit. I ...
0
votes
0answers
6 views

Pointer to Array of Strings as CONST? [migrated]

i program a application with mikroC PRO for AVR on the Hardware mikromedia for XMEGA. I have different languages to show on a TFT Display. I must switch the languages at runtime. This works the ...
0
votes
3answers
89 views

Does it make sense to have a separate init function?

I'm created an opaque type and I have two options for its management. The first looks like this: type_t *a = type_init(); int err; err = type_do(a, "foo", "bar", FLAGBIT1|FLAGBIT2, NULL); if (!err) ...
-6
votes
1answer
79 views

C program for Tree Traversal without Recursion [closed]

I want to write a C function for Tree Traversal without Recursion. The program that involves recursion is too simple, I want to do the same thing without recursion. I know the algorithm but couldn't ...
1
vote
1answer
45 views

The advantage of using __attribute__((aligned( )))

I found in more than one SIMD program the instruction __attribute__((aligned(16))) . When I looked for an explanation I found The keyword attribute allows you to specify special attributes of ...
6
votes
4answers
402 views

Undefined behavior, in principle

Whether in C or C++, I think that this illegal program, whose behavior according to the C or C++ standard is undefined, is interesting: #include <stdio.h> int foo() { int a; const int ...
-3
votes
0answers
35 views

Developing linux p2p applications [closed]

I have been tossing the idea around in the old noggin of creating a simple p2p chat application that would run in a linux environment and possibly be written in C. It's been awhile since I have ...
1
vote
2answers
120 views

How to abide the “allocate in caller” rule when the size is computed in the callee?

Let's say we have an opaque type handle_t that is managed through a simple interface with functions such as: handle_t *handle_init(void); int handle_do(handle_t *); void handle_free(handle_t *); ...
4
votes
2answers
83 views

Defining error codes

We are designing an error-handling framework for a cryptographic library written in C. The approach we are taking is that relatively few errors are propagated back to the user since on most occasions ...
-2
votes
1answer
119 views

Ambiguous If-else nested block in C without braces [closed]

Consider the following code in C: if(34) if(0) printf("Stat1"); else printf("Stat2"); Here,the first if condition is true,while the second if condition is ...
0
votes
1answer
166 views

Polymorphic engines in C and/or C++ [closed]

I stumbled across polymorphic engines and I don't know anything about them. However, I am curious about how they are written. Every example that I've looked up writes them in assembly, my assembly is ...
0
votes
1answer
62 views

Buffer-overflow vulnerabilities that a static code analyser won't pick up [closed]

I'll use FlawFinder in this example. FlawFinder is a static code "analyser" tool that examines C/C++ source files and outputs warnings/hits if a vulnerability was identified. The way it does this is ...
-2
votes
0answers
25 views

Problems Initializing a Struct at Declare Time Using Char Pointer [migrated]

I am trying to declare and initialize a struct using a char* pointer. Compiling the code below fails if I do anything but thing things[] = {{3,300},{4,*text}}; Linux gives me a core dump when it ...
3
votes
2answers
150 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 languages like C# ...
0
votes
0answers
49 views

Basic logical operator question [migrated]

#include <stdio.h> int main() { int k=5; if(++k < 5 && k++ / 5 || ++k <= 8) { printf("%d",k); } return 0; } Why is the output 7 and not 8?(I am a ...
-2
votes
1answer
109 views

Uniqueness of for loop [closed]

How does the for loop function is implemented so that it can accept ; as parameter separator rather than , which is trivial in normal functions.
8
votes
5answers
531 views

Are C static libraries frowned upon? [closed]

There are 2 arguments for having shared libraries: It helps reduce disk space. When a shared library is updated, all the binaries depending on it get the update. There is mainly one drawback for ...
1
vote
2answers
77 views

Microchip XC8: How to pack code against an upper limit?

I have a project for a PIC16F1454 that needs some custom linking. Basically, I've separated my code into two parts that can be downloaded separately in the field and thus update (almost) all of the ...
3
votes
1answer
215 views

Why did GCC switch from Bison to a recursive descent parser for C++ and C?

Was there a language change that required it or some practical reason why Bison was no longer appropriate or optimal? I saw on wikipedia that they switched, referring to the GCC 3.4 and GCC 4.1 ...
-1
votes
0answers
12 views

Problem with C code. Raspberry PI, HD44780 LCD [migrated]

I have been writing a program for interfacing a raspberry pi with a HD44780 LCD. The code I have wrote does not seem to initialise the display, from the datasheet as far as I can tell I am doing the ...
2
votes
2answers
107 views

In which stage of compilation is “typedef” resolved by the compiler?

There are different stages of compilation Such as Preprocessing stage Syntax analysis Semantic analysis Intermediate Code generation Machine Code generation Optimization Linking My question here ...
3
votes
1answer
123 views

How to fix legacy code that uses <string.h> unsafely?

We've got a bunch of legacy code, written in straight C (some of which is K&R!), which for many, many years has been compiled using Visual C 6.0 (circa 1998) on an XP machine. We realize this is ...
4
votes
7answers
979 views

Why do we need to include the .h while everything works when including only the .cpp file?

Why do we need to include both the .h and .cpp files , while we can make it works with making just a .cpp file and then including it . For example, Creating a file.h containing declarations, then ...
19
votes
12answers
5k views

Why does void in C mean not void?

In strongly-typed languages like Java and C#, void (or Void) as a return type for a method seem to mean: This method doesn't return anything. Nothing. No return. You will not receive anything from ...
0
votes
1answer
43 views

Macro guard in Objective-C

I have noticed that many famous libraries written in Objective-C (eg. AFNetworking) use the macro guard inside their header files. Im aware that the #import directive, which works exactly like ...
-2
votes
1answer
161 views

What are steps in making an operating system in C ? [duplicate]

I am trying to make an my own OS. This is for educational purpose only, so that I get to understand the internals as well as get a good idea of low level programming. I have some prior application ...
1
vote
2answers
191 views

Is goto to improve DRY-ness OK?

My code has many checks to detect errors in various cases (many conditions would result in the same error), inside a function returning an error struct. Instead of looking like this: err_struct ...
0
votes
1answer
104 views

comparison of an unsigned variable to 0

When I execute the following loop : unsigned m; for( m = 10; m >= 0; --m ){ printf("%d\n",m); } the loop doesn't stop at m==0, it keeps executing interminably, so I thought that ...
3
votes
3answers
113 views

Why are packed structures not part of the C language?

Every C compiler offers the option to "pack" C structures (e.g. __attribute__ ((__packed__)), or #pragma pack()). Now, we all know that packing is required, if we'd like to send or store data in a ...
-4
votes
1answer
110 views

Calculate Pi to N number of places [closed]

I am trying to work out how to calculate Pi to N decimal places, I think the default DP's for a float/double is 5 and then you have setprecision() however these are obviously inadequate, I need ...
2
votes
1answer
128 views

How to store satellite data in C data structutres

I've been reading through Introduction To Algorithms 3rd Ed, and am really enjoying the material; however, I am having difficulty in implementing some practical situations. It's not the theory, or ...
1
vote
3answers
73 views

Reconstructing a huffman tree using minimal information in the header

I'm writing a huffman encoding program in C. I'm trying to include the least amount of information in the header as possible, I know the simplest way to decompress the file in the header would be to ...
2
votes
3answers
186 views

C/C++: Which conversion warnings make sense in practice?

C/C++ implicit conversions can cause bugs. Here's one example: int foo, bar; scanf("%d", &foo); scanf("%d", &bar); float foobar = foo / bar; If I input 7 and 2, it's not 3.5 as expected - ...
6
votes
2answers
331 views

C programming practice, passing a pointer to a function [closed]

Consider the following C function which takes as argument a string, which is then stored inside a struct: struct mystruct* usestring(char* string) { struct mystruct *struct; struct = ...
1
vote
2answers
115 views

Implementing a simple controller in embedded C

Is there a known method or pattern to implement a simple controller for an MVC design in pure C or the switch case approach is the standard? Background : I have an embedded application and I'm ...
0
votes
2answers
115 views

boolean operations in C using bitfields

I am trying to implement boolean data type in C. Basically, I am working with sets. The following code can be used to access each bit but I am unsure whether I can represent sets using this method. ...
1
vote
1answer
163 views

What is this boolean law?

A friend of mine has shown sometime ago the name of the below boolean technique/law but I forget that name unfortunately. Does someone know what it's called? example in C language: !(a || b) It's ...
-1
votes
2answers
123 views

Reading assembly useful for insights when writing C/C++? [closed]

While in most cases its not necessarily, recently I have taken to reading the generated assembly of my C code every so often, when I'm curious as to the kinds of optimizations my compiler is making. ...
5
votes
2answers
226 views

Processor architectures for testing C/C++ portability

Currently I'm working on a C/C++ code-base which is fairly portable, it can compile on most Unix like systems as well as MS-Windows (MSVC), using various popular compilers. Previously I've found ...
4
votes
1answer
358 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 ...
20
votes
3answers
3k views

Why Increment Pointers?

I just recently started learning C++, and as most people (according to what I have been reading) I'm struggling with pointers. Not in the traditional sense, I understand what they are, and why they ...
1
vote
2answers
72 views

Is there a stricter strtoull() in any ubiquitous C library?

I want a function that will interpret a string as a strictly unsigned integer, failing when the string overflows, represents a negative number, or does not represent a number. strtoull() does set ...
-3
votes
1answer
107 views

Implementing keyword “const” [closed]

A constant pointer is a pointer which points to a fixed memory location throughout.The question is how do you ensure that this behavior is ensured without using the keyword constant while declaring ...
1
vote
4answers
166 views

What should I do and know before I start writing C? [closed]

I have a college degree in CS, and learned about Java and OCaml. Java was used as introduction, and in most CS classed, except the theoretical ones. OCaml was part of learning a different programming ...
2
votes
2answers
154 views

Why do binary files load quicker than alphanumeric text files?

I've noticed that when I load/store large data files in a binary format, the program runs much faster than if I load data from an ASCII encoded file. Why is this the case? The data in my case is ...