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

learn more… | top users | synonyms

15
votes
7answers
3k views

OO best practices for C programs

"If you really want OO sugar - go use C++" -- was the immediate response I got from one of my friends when I asked this. I know two things are dead wrong here. First OO is NOT 'sugar', and second, C++ ...
47
votes
8answers
5k views

Why does C provide language 'bindings' where C++ falls short?

I recently was wondering when to use C over C++, and vice versa? Fortunately someone already beat me to it and although it took a while, I was able to digest all the answers and comments to that ...
-5
votes
0answers
37 views

c# cannot insert data into database [on hold]

I tired to my code, i have no idea whats wrong with my code please help me to fix this This code should be insert the data into database, here im using ms access this is my file staff.cs using ...
15
votes
9answers
3k views

Can you “stop” a C program from being reverse engineered? [duplicate]

I'm sure that many of the middle to high level languages can be reverse engineered. But if a C program can be reverse-engineered, and turned back into editable source code, how do I discourage such a ...
-1
votes
0answers
26 views

Casting to pointer warning [migrated]

I defined variables display_address, version, serial_no[] as uint8_t and forwarded them to function, that variables need to be pointers so I casted it (uint8_t *)variable, and after that I'm getting a ...
0
votes
0answers
28 views

Best way to signal all child processes to terminate using C

I have been assigned the task of designing a simple web server using C in my UNIX & C class. The webserver listens and forks when a successful connection is made so that multiple clients may be ...
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 ...
2
votes
0answers
130 views

Have any C compilers ever *defined* `unsigned short x=-3; x*=x;` to yield anything other than 9

In a C implementation where int can hold all values of type unsigned short, standard integer promotion rules dictate that given the code: unsigned short x=(USHORT_MAX+1)-3; // Or just -3 x*=x; a ...
1
vote
1answer
74 views

Equivalent translation of Asynchronous behaviour in C

As a follow-up to my other question, if one were to build a general-purpose translator from a language that has support (be it with an external library or otherwise) for asynchronous behaviour to a ...
0
votes
0answers
12 views

c Programming, dynamic allocation + linked lists [migrated]

I am having trouble with this code, and i'm not sure what i'm doing wrong #include <stdio.h> #include <stdlib.h> #include <string.h> #include <time.h> typedef struct ...
4
votes
7answers
485 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
0answers
45 views

Lisp macros for c [closed]

I always thought Lisp macros are impossible in C. So can someone please explain me what this is?
-2
votes
1answer
108 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
1answer
60 views

Executable File Size Difference Between Python and C [closed]

Does using lower level programming languages have benefit of generating lesser file size when creating an executable, in contrast to using higher level languages for the same algorithm?
14
votes
2answers
8k views

Good unit test examples for embedded C developers [closed]

I'm going to be giving a talk to my department next week about unit testing and test-driven development. As part of this, I'm going to show some real-world examples from some code I've written ...
3
votes
1answer
126 views

Implementation of Asynchronous function call in C

I took it upon myself recently to work towards making a general-purpose Translator to automatically translate js programs into C, but I got stuck when thinking of asynchronous behaviour. Using ANSI / ...
-2
votes
1answer
57 views

how integer type can handle text stream (getchar()) in C? [closed]

While going through C programming by Ritchie and kernighan, I came across the following code. #include<stdio.h> int main() { int t; t = getchar(); while ((t=getchar()) != EOF) { ...
1
vote
2answers
270 views

Function calls to calls in windows api

When programming in Windows, how does Windows communicate with the programs that run on it? When you incorporate a function call which is in another memory location on the disk or memory (not a ...
15
votes
2answers
2k views

What happened to Concurrent C? [closed]

I recently checked out a fantastic book from my college library. It is a bit old at 1989, but the language it describes sounds rather nice. And even while I may not be using it soon, I wanted to ...
9
votes
4answers
736 views

What features did c get from c++? [closed]

What features were added to C that were originally in C++? When where they added and for what reason(what where the pro/con arguments)? How do they differ in C as compared to C++? Did the features ...
2
votes
2answers
221 views

How does printf write to stdout?

I've been looking for an answer to this for a couple days, and all of the results I've come up with are about how printf accepts an arbitrary number of arguments. How does printf write to stdout? ...
8
votes
5answers
1k views

When does it make sense to compile my own language to C code first?

When designing an own programming language, when does it make sense to write a converter that takes the source code and converts it to C or C++ code so that I can use an existing compiler like gcc to ...
-1
votes
1answer
108 views

Understanding the solution of exercise 1.16 of K&R as given in the “The C Answer book”

The exercise 1.16 in K&R's book asks, Revise the main routine of the longest-line program so it will correctly print the length of arbitrary long input lines, and as much as possible of ...
0
votes
3answers
230 views

Socket Connecting to Large number of IPs

I have a text file of ~600 CIDR notation IP blocks which, when expanded, amount to ~17.5M IP addresses. I need to socket connect to each one. If it connects, I add it to a "live" list, if it returns ...
-1
votes
2answers
93 views

In C is it possible to change http requests to https [closed]

Long story short I've got this package that currently has a security risk where credentials are sent over http and I need to convert them to https but I currently lack the knowledge to do so. Could ...
-1
votes
0answers
32 views

int differers in level of indirection from char error [migrated]

The code is from Absolute beginner's guide to C, and I get this error ./BlackJack.c<41> : warning C4047: '==' : 'int' differes in levels of indirection from 'char [2]' when I try to compile it ...
16
votes
8answers
936 views

Is directly using Make considered obsolete?

So I have been coming across many comments/posts/etc regarding creating makefiles directly, and how it is a silly thing to do in 2015. I am aware of tools such as CMake, and I actually use CMake quite ...
1
vote
5answers
396 views

How to share memory between applications written in C/C++

I'm going through a program written in C/C++ for control in robotics. Basically, three different programs run at the same time, and they communicate via shared memory. Google-ling around I found ...
1
vote
2answers
493 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 ...
1
vote
3answers
5k views

Tips on Converting a C program to Pure Python [closed]

I'd like to convert an open source C application to pure python (not to Cython, IronPython etc). The documentation and presentations of the original creator of the C application has given me a good ...
0
votes
0answers
120 views

Why does this execute a jump instruction? [migrated]

I have just seen a very interesting C code in the boot loader of a small embedded product. The code consists of two parts: boot loader and the main code. The start of the main code address is stored ...
49
votes
13answers
3k views

Philosophy behind Undefined Behavior

C\C++ specifications leave out a large number of behaviors open for compilers to implement in their own way. There are a number of questions that always keep getting asked here about the same and we ...
11
votes
1answer
224 views

What are the absolute, minimal requirement for containing SE Asian charsets for an embedded system project?

I work for a company that has begun integrating embedded computer systems into our products that we manufacture. We have a pretty wide range of products and they are distributed across the globe. ...
0
votes
0answers
52 views

Abstract Web API from validation and configuration management in embedded system

Im working with embedded Linux for a router. There is a web GUI for the user to configure router options. When user fill a web form this is submitted to a web server function that is responsible of ...
2
votes
1answer
211 views

How can C++ make it possible to use dynamic container classes even in embedded systems?

How can C++ make it possible to use dynamic container classes even in embedded systems? Background info: I've been working with PIC (C) and AVR (C++) processors and at the moment (PIC C) I'm ...
0
votes
1answer
129 views

Has pre-increment operators become that common? [closed]

Bit of background to explain the reasoning: I've been programming for a good while, but took a break between 2012 and 2014 for other stuff. Before that break, I would hardly ever hear about "++i", let ...
0
votes
2answers
90 views

Idiomatic C API with regards to pointers

I am trying to get a better understanding of how one would structure an API in C. I create a struct Person I have a init function that sets data on that struct I have multiple "helper" functions ...
0
votes
0answers
14 views

Threads to print numbers sequencially : with even and odd threads running parallely [migrated]

I am new to multithread programming. I tried to print numbers sequentially using even and odd number printing threads, running in parallel. When executed, the code enters a deadlock. Can anyone help ...
0
votes
2answers
83 views

forking but not exiting

It is normal for the child in a fork() to call exec() or _exit(). Are there any realistic scenarios where the child might return from the function that called fork() instead? void foo() { pid_t ...
1
vote
3answers
221 views

Alternative to goto-statement in this case? [duplicate]

Currently I am using gotos for closing handles and general cleanup if an error occurs. Since I don't want to nest all the ifs and a function for cleanup would require a return besides the cleanup(); ...
6
votes
2answers
1k views

Why is C still in the category of High Level Language? [closed]

Many of the textbooks on the C programming language tell that C is a high-level programming language, but many of the tutors online say that C is also a middle-level programming language. Why is it ...
55
votes
5answers
11k views

Why are there so few C compilers?

C is one of the most widely-used languages in the world. It accounts for a huge proportion of existing code and continues to be used for a vast amount of new code. It's beloved by its users, it's so ...
2
votes
2answers
92 views

Function naming design in a C Library

I'm writing a C (c99) library that operates on strings. I'm having a design problem writing functions that will perform in different modes. For example; the Find function can search for: the ...
5
votes
5answers
3k views

Is it better to use preprocessor directive or if(constant) statement?

Let's say we have a codebase that is used for many different costumers, and we have some code in it that is relevant only for costumers of type X. Is it better to use preprocessor directives to ...
-3
votes
1answer
47 views

Passing Parameters to pthread_create [closed]

I have a structure named graph. graph *G; Now I create memory of size of structure using malloc and the start pointer is stored in pointer G. G = (graph*)malloc(sizeof(graph)); My question is ...
4
votes
1answer
216 views

Should I always return an error code from C functions?

I have the following code in many places in a large application: if (datastruct.data_ok && cur_time > datastruct.start_time && cur_time < datastruct.end_time) { ...
12
votes
5answers
2k views

Advice for an ambitious student on building your own kernel [closed]

I'm a very ambitious university student who wishes to learn pretty much everything there is to know about computers (bash me if you want, I love learning). Recently I thought it would be a fun project ...
0
votes
0answers
68 views

Writing Z80 table based assembler/disassembler

I have a long-term project: DIY computer with various processors. One of my wishes not only make hardware, but software too. So I started from assembler/disassembler for Linux, though there is a lot ...
0
votes
1answer
134 views

Can i create a function with variable parameters in C?

I've always wondered where a single function such as printf(); can take in variable parameters and provide the right results. For example, printf("Number is %d",a); which has two parameters, and ...
0
votes
2answers
1k views

Assigning strings to pointer in C Language

I am a new learner of C language, my question is about pointers. As far i learned and searched pointers can only store addresses of other variables, but cannot store the actual values(like integers or ...