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

learn more… | top users | synonyms

-6
votes
0answers
23 views

C programming explanition

I would like to ask you why part 2 = 2 3 -2 and part 3= 3 3 9. I know the answer of the part 1 please explain. when I compile, I get the answer. but i did not understand the rest of that. #include ...
-4
votes
0answers
38 views

x86 assembly books; but looking for something slightly different [on hold]

Are there Assembly tutorial books that clearly explain the relationships between a high level programming language and the x86 assembly language during compilation ? For example, I know a very good ...
7
votes
4answers
1k views

The need for Explicit Type Conversion in C#

Consider the following code: DerivedClass drbObj = (DerivedClass)obj; Here obj is of type Object and this is reasonable since Object is the base type of every Class in C#. Here, since the type of ...
5
votes
1answer
130 views

Kth selection routine - Floyd Algorithm 489

I have recently come across a promising Kth selection routine that reportedly outperforms quickselect the Floyd, Rivest Select routine. This Wikipedia article provides a pseudocode version which I ...
-3
votes
0answers
19 views

Cuda code doesn't seem to Launch the Kernel [on hold]

I'm trying to compile the next CUDA code, everything goes well with the command: nvcc -o test.exe test.cu, but the problem is that when I execute the program doesn't seem to launch the kernel ( I ...
0
votes
0answers
20 views

Synchronizing content between web-based app and game server

I have a MUD server, written in C, that I'm trying to move from file-based storage to MongoDB. Eventually, I'd like to offload administration of game content and settings to a web console, written in ...
-2
votes
1answer
48 views

Copying desired bits from variables [closed]

What's the best way to copy desired bits from char, int or any other variables? I want to see all possible and the most efficient techniques for this purpose. I have for example 16bit variable 0000 ...
4
votes
4answers
3k views

What is important when optimising for the CPU cache (in C)?

Reading these two questions, I see that understanding CPU caching behaviour can be important when dealing with large amounts of data in memory. I would like to understand the way the caching works to ...
5
votes
2answers
100 views

What is a reasonable level of detail for a style guide? [closed]

We are developing embedded software for an automotive product in ANSI-C in a large team. Yesterday, in our regular code review, we had a general discussion about the style of our code. We have a ...
-4
votes
0answers
34 views

Operating Systems Programming Project : (Bus) Inter Pprocess Communication [closed]

I have a project in operating system programming (Lunix) using c language , may anyone help me , please , This is the project description : implement a new inter-process communication method called ...
9
votes
6answers
3k views

Can you learn functional programming in C?

As a result of the comment discussion here, I wonder whether you can learn Functional Programming in C?
15
votes
5answers
82k 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 ...
2
votes
2answers
71 views

Compiling and deploying a C program to an MCU running an RTOS

Please note: Even though I'm specifically talking about an RTOS called Embox here, and even though I'm talking about AVR/ARm, I think this question can be answered by anybody whose ever done a fair ...
2
votes
0answers
145 views

Embox compilation and flashing [migrated]

I am interested in attempting to compile, package and flash Embox to an MCU, from either a Windows or Mac machine (cross-compilation), via JTAG, and I have a number of concerns. Observe what I ...
-1
votes
0answers
4 views

Reccursive function of the sequence $$U_n=\frac{1}{3} (\frac{A}{U^2_{n-1}} + \frac{1}{U_{n-2}})$$ [migrated]

#include<stdio.h> #include<conio.h> #include<math.h> void triple_root(float B[1000],int i,float A,float b,float c) { float x; x=0.333*((A/(b*b))+(1/c)); ...
-4
votes
0answers
29 views

What is difference between hex and char array print? [migrated]

I have written following programe in c #include <stdio.h> char str[]="hello world"; unsigned char hexvalue[] = {0x01,0x02,0x03,0x04,0x05}; int main() { int i; printf("string %s \n", ...
1
vote
2answers
505 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 ...
2
votes
2answers
89 views

What are the benefits of a device driver when I can access the I/O registers directly?

I was interested in what modern, C-based, Linux device driver development looked like, and so I took a good gander at this excellent article. I didn't read every single line, but perused the majority ...
6
votes
8answers
699 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
1answer
58 views

Compiling and deploying RTOS to an MCU

Please note: Even though I'm specifically talking about an RTOS called Embox here, and even though I'm talking about AVR/ARm, I think this question can be answered by anybody whose ever done a fair ...
3
votes
2answers
94 views

Benefits of RTOS vs Bare Metal for MCU Programming?

Please note: This question specifically mentions two RTOSes but is more generic and can probably be answered by anybody who has written C code for embedded RTOSes before, and had their software run ...
6
votes
5answers
742 views

Should functions of a C library always expect a string's length?

I'm currently working on a library written in C. Many functions of this library expect a string as char* or const char* in their arguments. I started out with those functions always expecting the ...
0
votes
0answers
45 views

GMP Core Dump while using mpz_clear in C

I'm working on a prime factorization program written in C using the GMP library through cygwin. The algorithm that I have now works fine, but has memory leaks from not using the mpz_clear function on ...
15
votes
7answers
3k views

OO best practices for C programs [closed]

"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++ ...
48
votes
8answers
6k 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 ...
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
50 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
149 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
76 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 ...
-2
votes
1answer
115 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
69 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
143 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
58 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
273 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 ...
2
votes
2answers
230 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? ...
9
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
112 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
236 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
95 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 ...
17
votes
8answers
962 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
469 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
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 ...
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
59 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 ...