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
13 views

Why NOP/few extra lines of code/optimization of pointer aliasing helps? [Fujitsu MB90F543 MCU C code]

I am trying to fix an bug found in a mature program for Fujitsu MB90F543. The program works for nearly 10 years so far, but it was discovered, that under some special circumstances it fails to do two ...
-1
votes
1answer
48 views

How to create user defined conditional statements in c?

I have two stacks s1 and s2 with numbers stored in them. I have a function(say comp) which compares the numerical values of s1 and s2. I want to know if it is possible to modify the function so that ...
0
votes
0answers
3 views

Initializing a pointer in struct in at minimum lines [migrated]

I'm currently new to C programming, and appreciate for any tip. Is there a shorter way to initialize struct pointers in C without removing the pointer tags? Thanks~ typedef struct { int x, y, z; ...
-4
votes
0answers
44 views

Receiving udp packets from two remote machines [on hold]

The setting is as follow : i am listening (as machine 1) to two remote machines ( 2 and 3) using 'recvfrom()' (C socket API), i get a message from machine 2 then i delegate to machine 3, machine 3 and ...
-4
votes
0answers
27 views

I need Help making a flowchart [on hold]

I have never made a flowchart before and have no experiance of it. I know what standard symbols and their meaning but I need some examples. If anyone can convert the following code in flowchart form ...
-4
votes
0answers
35 views

I want to switch my programming platform [on hold]

I have worked as a ASP.NET developer(Web) for 4 years and I waked on Desktop applications as well(WPF). As everyone knows many things are taken care by .net framework and by Visual Studios, as days ...
0
votes
3answers
117 views

Understanding the concept of “arguments” and “parameters” in C language as explained in K&R The C Programming Language

In the third last paragraph at page number 26 of the ebook "The C Programming Language" the author(s) say, "We will generally use parameter for a variable named in the parenthesized list in a ...
-3
votes
0answers
32 views

The C Programming Language (C&R) ex1-20 . I encounter some trouble [migrated]

/* * 1-20. Write a program detab that replaces tabs in the input with the proper number * of blanks to space to the next tab stop. Assume a fixed set of tab stops, say every n columns. * Should n ...
1
vote
0answers
10 views

Unexpected snprintf behaviour [migrated]

I noticied a (to my opinion) very strange behaviour of snprintf on several platforms. Consider the following code (minimum working example which causes the observed behaviour): #include ...
-4
votes
0answers
55 views

How to fix segmentation fault? [closed]

The following is a function in my C program. When I debug the program using gdb, it is said that there is segmentation fault in the function. But I don't know where is the problem. This function is ...
-1
votes
0answers
57 views

The proper use of continue [closed]

i just want to ask a simple question. i have a doubt that how a continue statement works means that if i use it in a loop. and i know that If the continue statement is inside nested structures, it ...
3
votes
3answers
82 views

sorting / merging hashtable

For my project I have a hashtable with 1M buckets (sometimes more). Each bucket contains lots of values and they are stored sorted in a dynamic array. I am looking for easy enough way to store all ...
0
votes
1answer
161 views

Exercise in 1.6 C by Kernighan and Ritchie

I'm using this book by Kernighan and Ritchie, on the chapter about character input and output and file copying, I'm totally lost as to what this chapter is talking about. This question may seem too ...
0
votes
2answers
195 views

What kind of applications are built using C [closed]

I studied C programming about ten years ago, whiles in Uni,however I would like to pick it up again. I'm looking at developing secure applications that utilize cryptography. Would C be the right ...
-1
votes
0answers
14 views

program in c with strings [migrated]

i have a problem with this code i need to scan strings till i give the char 0 and count how many words with 1 char,2,3... etc here is my code : it never stops include include int main() { ...
3
votes
4answers
250 views

int * vs int [N] vs int (*)[N] in functions parameters. Which one do you think is better?

When programming in C (or C++) there are three different ways to specify the parameter in a function that takes an array. Here is an example (implementing std::accumulate from C++ in C) that shows ...
0
votes
2answers
115 views

How much does C help you in other languages? [duplicate]

How much does learning C to moderate level help you as a programmer. For example, does being competent in C make it easier to pick up languages as time goes on and get a better understanding of them?
0
votes
0answers
10 views

Problem with #include<graphics.h> [migrated]

I am trying to compile a program which includes the graphics.h header file for C. I have added the graphics.h and winbgim.h header files in the include folder and also libbgi.a to lib folder. Just ...
1
vote
1answer
128 views

How to represent “class” data type in C or any low level language? [closed]

I'm writing a simple language compiler,currently it's support functional programming only. I want to support OOP concept, but I don't know how exactly I can represent an object ? just where to start ...
-2
votes
0answers
17 views

Please tell me where I've gone wrong [migrated]

#include <stdio.h> main() { char name1[15],name2[15],name3[15]; int no; printf("Enter the serial number and name one\n"); scanf("%d %15c',&no, name1"); printf("%d %15s\n\n",no,name1); ...
3
votes
2answers
187 views

Is it always safe to shift bool values?

I stumbled about a Cppcheck warning (an inconclusive one), that I mistakenly used & instead of &&: /// @param code identifies the command. Only the lower 16 bits of are being processed ...
4
votes
1answer
128 views

Using macros to protect assignment to global variables

Because there is no language feature in C to protect assignment to global variables would you recommend doing something like this? Take this example: We have a module with the header file called ...
0
votes
1answer
127 views

(almost) Pure C instead of C preprocessor [closed]

Why isn't (almost) pure C used instead of the C preprocessor? Sure I understand it would be a little more verbose. For example: #define PI 3.14159 If we had regular C as preprocessor language, the ...
0
votes
0answers
79 views

C: Using `extern const` in header files to make global variables read only [migrated]

I was experimenting with GCC and found out that you can declare variables const in header files but keep them mutable in implementation files. EDIT: This does actually not work, check my own answer. ...
3
votes
0answers
57 views

Proper way of handling EINTR in libraries

What is the recommended etiquette when it comes to EINTR in libraries? I'm currently writing a function that does some file system tasks with the POSIX API, but a lot of the calls I use can ...
0
votes
0answers
3 views

Out of bound array elements being printed using gcc in Win8 [migrated]

I'm compiling the following code in my m/c using codeblocks and mingw32-gcc.exe v.4.8.1(tdm-2). #include <stdio.h> #include <stdlib.h> int main() { int a[8] = {3,1,10,-1,7,2,-8,1}; ...
4
votes
1answer
152 views

Using macros to implement a generic vector (dynamic array) in C. Is this a good idea?

So far I have only done personal projects at home. I hope to get involved in some open source project some time next year. The languages I that have been using the most are C and C++. I have used both ...
6
votes
2answers
937 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 ...
2
votes
5answers
258 views

Why C language is taught as the basis of Computer Programming Languages? [duplicate]

I often wondered why C Language is taught as the basis of programming languages everywhere. There are a lot of modern languages like Java, Python etc. which makes the syntax and programming easier. ...
-1
votes
0answers
95 views

Can someone clarify strings for me in the C programming language [migrated]

Hey guys so I'll cut this short. A few weeks ago I started learning the programming language C. I have knowledge in web technologies like HMTL/CSS, Javscript, PHP, and basic server administration. ...
4
votes
3answers
183 views

Safety-critical software and optimising compilers

I'm reading some internal documentation for code developed to the MISRA C guidelines, and I see that in compiler flags section of the documentation there is a note to compile with optimisation off ...
3
votes
1answer
49 views

Bottleneck performance in ECS

I've been looking into building an entity-component-system. Basically, an entity is just an id wrapped around a struct, components are data belonging to that entity(and reference said id), and systems ...
13
votes
5answers
2k views

Why is *declaration* of data and functions necessary in C language, when the definition is written at the end of the source code?

Consider the following "C" code: #include<stdio.h> main() { printf("func:%d",Func_i()); } Func_i() { int i=3; return i; } Func_i() is defined at the end of the source code and ...
1
vote
2answers
253 views

Disadvantages of Pointers [closed]

I was wondering why pointers are not included in modern languages now-a-days. I already did research on this on internet, and found out few theories/reasons: Memory leakage is the biggest concern ...
110
votes
6answers
20k views

Is every language written in C?

Sometimes while programming in different languages (C/C++, C#), this thought comes to my mind: Is each and every language written in the C programming language? Is the C language the mother/father ...
4
votes
1answer
179 views

Why define struct in variable?

Consider the following program: Many people when they want to use a struct, they create a new variable as: struct structureName variableName While it works when you just define it as: ...
-3
votes
1answer
37 views

How can this allocation of bi-dimensional arrays work?

I was seeing this post on StackOverflow and saw a new way (at least for me) to define a two dimensional array of 5x5, it works well, but I feel I don't understand what is going on in the background. ...
1
vote
3answers
129 views

Use of for loop conditional statement unrelated to iterating variable

Is it considered decent form to write code like this: int done = 0; for (x = 0; !done; x++) { ... something involving 'x', that might end early ... if (!(x < max)) done = 1; } ...
1
vote
3answers
78 views

Question about multidimensional arrays

I was wondering something about the multidimensional arrays and then I got a doubt about a concept, specifically about their representation on memory. For example, an array can be defined as follows. ...
1
vote
2answers
233 views

Searching algorithm used in switch statement

What is the searching algorithm used in switch statement in C language? If the cases are not in order still it searches proper case which means it is not a binary search algorithm, can anybody ...
0
votes
1answer
107 views

Introducing function waypoints to protect device [closed]

Defining a magic pointer or counter inside a program / class and checking for a fixed value before executing critical commands is a way to generate a barrier against wrong execution. This check is ...
-2
votes
1answer
84 views

Printing value of atoi of an array - what does the number mean? [closed]

Simple question, below is my code. The number my compiler returns is 4219296. My question is: why? What is my code doing here? #include <stdio.h> int array[]; int main() { atoi(array); ...
16
votes
4answers
2k views

Why do we have to mention the data type of the variable in C

Usually in C, we have to tell the computer the type of data in variable declaration. E.g. in the following program, I want to print the sum of two floating point numbers X and Y. ...
3
votes
4answers
358 views

Why do we have to tell printf() the type of data in C?

Let's consider this C code: #include <stdio.h> main() { int x=5; printf("x is "); printf("%d",5); } In this, when we wrote int x=5; we told the computer that x is an integer. The ...
-2
votes
2answers
87 views

Using a global struct with pthreads in C [closed]

I'm trying to simulate clients going into a bank and being served by tellers over a period of time. I am using a thread to determine if a client came into the bank via an arrival rate and am using ...
-5
votes
3answers
80 views

Some tips on creating programs in C? [closed]

So I'm currently in my first year in university studying electrical engineering. I'm taking a intro to C course, and I'll say it now, I'm not sure if I'm going to be able to pass the exam. Even with ...
3
votes
1answer
118 views

Exceptions in ANSI C

Would it be possible to implement exception mechanism in pure ANSI C similar to the one used in popular OOP languages (with familiar try-catch-finally clauses)? If yes then how? I'm especially ...
0
votes
0answers
43 views

type name for state machine state (as opposed to other state variables)

I need to create a typedef for a state machine state, e.g. enum ToasterStateMachineState { TSM_READY, TSM_TOASTING, TSM_DONE }; But ToasterStateMachineState seems verbose and redundant; is ...
4
votes
1answer
112 views

What is grouping?

In the introduction to K&R there is the following text: Similarly, C offers only straightforward, single-thread control flow: tests, loops, grouping, and subprograms, but not ...
0
votes
3answers
166 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 ...