C is a general-purpose computer programming language used for operating systems, games and other high performance work.
0
votes
0answers
29 views
FizzBuzz variation
I am trying to solve the following problem
You are in room n (1 ≤ n ≤ 10^8, n ∈ N) and want to reach room 1 as fast as possible. You can move to n-1 and n+1 in a unit of time. Some rooms have ...
-3
votes
0answers
22 views
Question related to Logic [on hold]
Will Someone explain me the correct logic of this program?
/*Evaluate a,b,c,d*/
#include<stdio.h>
#include<conio.h>
int main()
{
int a=1,b=1;
int c= a || -- b; ...
-1
votes
0answers
17 views
SQLBindParameter and SQLExecute returns SQL_NEED_DATA [migrated]
I'm working on a C application that interacts with a mssql database running on Windows 2008 R2. I'm able to connect to the database and run specific queries, but when i use SQLBindParameter things ...
-5
votes
0answers
24 views
Get return value of shell script [on hold]
How to get return value from shell script that we launched to C code, and to get return value from shell script which already runs in background processes?
-4
votes
0answers
18 views
GTK installation on windows 7 32 bit [on hold]
I am trying to install GTK on windows7 machine and 32 bit. I managed to install the Msys32. After reading the help I found that I have to run some commands from the command prompt for complete ...
-4
votes
0answers
29 views
Attempting to create multiple if-else conditions [migrated]
I am writing a program that involves checking the validity of a date. I have set the conditions for the months which have 31 days in them, and I have set the conditions for the months which have 30 ...
0
votes
2answers
68 views
How does the LLVM compiler treat arithmetic operations in parentheses?
When it sees the parentheses, does it have the machine do the operations in the parentheses first, or does it distribute out the parentheses?
Like, if I have the following line of code:
int i = 2 * ...
-3
votes
2answers
121 views
Best x86 processor(computer) to learn computer architecture and assembly [on hold]
I'm planning to build a computer as a hobby from scratch, with the least basic hardware possible in functionality so I can learn the basics of computer architecture and assembly language.
I already ...
-4
votes
0answers
34 views
Message passing in procedure orinted programming language [on hold]
Why procedure oriented languages do not support message passing like c++,java?
I know message passing in object oriented programming language. But i confused that whether procedure oriented ...
0
votes
2answers
189 views
Mixing OOP and Non-OOP
I'm working on a command line interface text based game. I'm writing it in C but there are various ways in which I could refactor the code by using Objective-C:
using NSDictionary to allow me to ...
0
votes
2answers
59 views
C: How does struct node * next work? [closed]
In C, for creating linked list we write:
struct Node{
int data;
struct Node* next;
};
So, my understanding is "struct Node* next" is a pointer variable of "Node" datatype.
But how does it point to ...
-2
votes
1answer
70 views
When to use typedef in C programs? [closed]
I'm learning C programming language... I discovered recently the typedefkeyword...
When is the right time to use it in a C program?
And this is an example:
typedef struct Books
{
char ...
3
votes
2answers
191 views
Methods of “Code Softening” (Opposite of “Hardening”) for C & C++ [closed]
Some developers work on code hardening.
(protecting against errors, you can build with a stack protector for example).
However, if you're trying to redo a strange someone else reports, or find ...
6
votes
0answers
1k views
How is memory managed for non-declared entities in the C language? [migrated]
For example: In the following code, how and where is the number '10' used for the comparison stored?
#include<stdio.h>
#include<conio.h>
int main()
{
int x = 5;
if (x > 10)
...
1
vote
2answers
136 views
Does printf in C99 automatically round numbers for me? [closed]
Does printf in C99 automatically round numbers for me? I wrote a program as shown below and I am getting unexpected output.
#include <stdio.h>
#include <math.h>
int main(void)
{
...
0
votes
2answers
287 views
How are complex programs made? [duplicate]
I know a few languages, and can program in them. How do multiple languages blend together in a single program? For ex. https://github.com/facebook/watchman. This uses C, PHP, Python, Javascript, etc. ...
1
vote
2answers
103 views
Will issues arise packaging libc and pthread with your C apps?
The issue I hit, is that I am packaging shared libraries with my code in order to load GNUTLS, except for libc, because I figured any system will have it. Most of them don't have the required 2.14 for ...
3
votes
6answers
580 views
Design decisions while porting a non object-oriented C program to Java
Background:
My boss made a comment on porting a C program that acts as some a simulator that communicates with a remote process through sockets to Java. He didn't assign it to me, or to anyone for ...
0
votes
2answers
100 views
why use postfix /prefix expression instead of infix?
I understand how to convert infix to postfix/prefix but I do not understand why postfix or prefix expression are used in computer system?
What is the advantage of postfix prefix over infix ...
1
vote
4answers
125 views
When is an object passed to a function?
Trying to clearly state the semantics of a function call.
In calling a function, are the arguments passed to the function the ones the calling code initially gives or the ones the function ...
21
votes
6answers
2k views
Why use an opaque “handle” that requires casting in a public API rather than a typesafe struct pointer?
I'm evaluating a library whose public API currently looks like this:
libengine.h
/* Handle, used for all APIs */
typedef size_t enh;
/* Create new engine instance; result returned in handle */
...
16
votes
3answers
584 views
Why are C string literals read-only?
What advantage(s) of string literals being read-only justify(-ies/-ied) the:
Yet another way to shoot yourself in the foot
char *foo = "bar";
foo[0] = 'd'; /* SEGFAULT */
Inability to elegantly ...
1
vote
3answers
136 views
Are file-scope `static` variables in C as bad as `extern` global variables?
In C, you'd often/sometimes (as a matter of style) use a file-scope static variable where you'd use a private class member variable in C++. When scaling to multithreaded programs, simply adding ...
1
vote
1answer
45 views
What is the most efficient way to discover devices on a network?
I've been programming a C web server from scratch as an interface for controlling ESP8266 WiFi modules that I plan to use to control appliances & lighting with relays. In an attempt to make a ...
4
votes
5answers
762 views
Checking array size in C/C++ to avoid segmentation faults
So it's well known that C does not have any array bounds checking when accessing memory. Nowadays, if you call myArray[7] when you initialised it as int myArray[3], your program will get a segfault ...
4
votes
1answer
96 views
How to abstract from a display?
I'm building an embedded text editor consisting of a keyboard, an LCD display and a PIC32 microcontroller, to be programmed in C. The application should look, for example, like the GNU nano editor. ...
1
vote
3answers
436 views
C: “this” vs “<instance name>”
I'm using C in a minimal, efficient OOP style to build a game engine. A problem I've begun to face as the engine code settles is my (erstwhile) choice to use this. For example, I have:
void ...
0
votes
2answers
78 views
Proper way to interpret this dereference operation?
I've seen this example in a text book and am a little confused how to interpret the operator precedence rules. Given this struct:
typedef struct {
char *data;
size_t start, end;
} ...
56
votes
14answers
7k views
Are data type declarators like “int” and “char” stored in RAM when a C program executes?
When a C program is running, the data is stored on the heap or the stack. The values are stored in RAM addresses. But what about the type indicators (e.g., int or char)? Are they also stored?
...
-2
votes
1answer
63 views
What's an effective threading structure for NIO and server performance in C/C++? [closed]
I run into this issue where if I do a read to check for data too often, my CPU skyrockets, and if I don't check often enough, it's slow for client performance. What's an effective way to deal with ...
5
votes
4answers
319 views
When did Undefined Behavior in C jump the causality barrier
Some hyper-modern C compilers will infer that if a program will invoke Undefined Behavior when given certain inputs, such inputs will never be received. Consequently, any code which would be ...
2
votes
6answers
742 views
Replacing C with JavaScript as an introductory programming language [closed]
I am a new teacher at polytechnic where we teach web development and basic software programming.
For years, the institution where I teach have taught C as their introductory programming language to ...
0
votes
0answers
57 views
A callback for when data is received?
So, my understanding is that the Kernel could receive TCP at any time, and that generally a C program asks the Kernel synchronously/asynchronously if it has data available. Would it be possible for a ...
1
vote
1answer
161 views
What would be a reason not to embed JS in C? [closed]
I'm working on an opensource application that processes JSON in C, because I would like to make it easier for people to help me in the project and because JSON is so close to JS. I want to embed a JS ...
1
vote
2answers
67 views
What should JITed bytecode do exactly?
I'm working on a VM (and a scripting language for it) that I plan to implement JITing for. I'm only working on the "plumbing" of it now, but I don't want the JIT compiler to be an afterthought. ...
2
votes
1answer
152 views
Endianness at bit level
I am learning the union and struct and I wrote the code below. What I do not understand is why the output is different when I change from a little endian to a big endian machine.
My understanding is ...
2
votes
1answer
156 views
What is the motivation for casting a pointer into a integer?
I'm doing some changes in the Linux kernel code and have noticed a pointer being cast into integer.
Check out buf below (full code):
snd_pcm_sframes_t snd_pcm_lib_read(struct snd_pcm_substream ...
3
votes
2answers
178 views
Why dynamic memory allocation functions in C returns void*?
Consider the prototypes of C's dynamic allocation functions
malloc - void* malloc(size_t size);
calloc - void* calloc(size_t n,size);
realloc - void* realloc(void* ptr,size_t newsize);
Now a ...
27
votes
5answers
2k views
Should I initialize C structs via parameter, or by return value? [closed]
The company I work at is initializing all of their data structures through an initialize function like so:
//the structure
typedef struct{
int a,b,c;
} Foo;
//the initialize function
...
1
vote
2answers
85 views
Multi-pattern matching
I have a given byte array in C and I need to match it against several byte arrays and return true if there is any match.
I can make various memcmp's but I feel that it is very inefficient.
Do you ...
2
votes
0answers
256 views
Fast fixed-size (256 bit) integer modulo/division
What is the fastest way to divide two 256-bit integers? They are represented as an array of 26-bit words, each stored in 32-bit integers. I have access to a 64-bit type if that's useful.
It seems ...
0
votes
2answers
178 views
In C, how are functions accessible if they're not inline or called by #include? [closed]
I'm looking at code that somehow calls a library but I don't see it calling any of the library's headers at any point. I've done searches within the code and I don't see anywhere the functions, ...
-1
votes
2answers
153 views
How does the post increment operator work in GNU C? [closed]
While the run the below program in Turbo C compiler, I am getting the expected output, however, when I run the same program it using "gcc" compiler in linux, it is giving an unexpected output!
int ...
1
vote
3answers
233 views
What does the “t” in int32_t signify?
In C, what meaning, if any does the t at the end of integer types like uint8_t and int32_t have? Where did it originate? Why wasn't the type just called int32?
12
votes
1answer
369 views
Why using sizeof of type to calculate the number of elements in an array is considered inferior to using sizeof of an element?
I'm reading "King K.N's C programming" and I'm reading the following statement:
We discussed using the expression sizeof(a)/sizeof(a[0]) to calculate the number of elements in an array. The ...
1
vote
3answers
116 views
How much can you detect undefined behaviour using testing [closed]
I hope this question fits this site.
You may know you can't detect undefined behaviour in C using compilers - and some tools (static analysis) can help you detect it.
My question is more empirical - I ...
1
vote
1answer
217 views
Inserting C++ code into C [closed]
What I need to do before inserting C++ code into C, and how to do it? Are there any examples to show me how this can be done. I have a good knowledge of C, but never mixed those two.
Thanks for the ...
0
votes
1answer
105 views
floating-point number stored in float variable has other value [duplicate]
I'm reading a book about C programming By "King.K.N" and I'm reading the following statement:
If we store 0.1 in a float variable, we may later find that the variable has a value such as ...
3
votes
1answer
371 views
How do C/C++ programs get ported to different platforms? [closed]
Java applications can run on different platforms because they always run on top of a Virtual Machine specifically developed for each platform. So, there's no native installation, you just drop the ...
0
votes
2answers
120 views
What's the simplest way to deal with events in C in this situation?
I'm writing a text-based game, in C. I want the game to handle NPCs movement and actions in the background, while the user is making his moves. I'd also use time-based events to tell the user when ...