Category "c"

What is the difference between using a Makefile and CMake to compile the code?

I code in C/C++ and use a (GNU) Makefile to compile the code. I can do the same with CMake and get a Makefile. However, what is the difference between using a M

Dividing arbitrary large numbers stored in char arrays in C

A part of my home assignment requires dividing large integers that are so long I can only store them in character arrays. Both the divident and the divisor can

Closing libUV Handles Correctly

I'm trying to find out how to fix these memory leaks I'm getting while running this program with Valgrind. The leaks occur with the two allocations in nShell_cl

Which type of #include ("" or <>) when writing a library in C/C++

I am writing a library in C++. The library has multiple headers and cpp files and needs to be cross platform (Windows Visual Studio and Linux gcc). When built t

What is Biased Notation?

I have read: "Like an unsigned int, but offset by −(2^(n−1) − 1), where n is the number of bits in the numeral. Aside: Technically we co

Does gcc initialize long strings to `""` but not short ones?

Note: I know that reading an uninitialized string is undefined behaviour. This question is specifically about the GCC implementation. I am using GCC version 6.2

Which one is safer to use? " ==TRUE" or " != FALSE"

Is it better to compare a boolean type variable with: == FALSE and != FALSE; or == TRUE and != TRUE?

Implementing matrix operation using AVX in C

I'm trying to implement the following operation using AVX: for (i=0; i<N; i++) { for(j=0; j<N; j++) { for (k=0; k<K; k++) { d[i][j] += 2 *

XINU OS - Understanding roundmb function

I am studying XINU OS, and came across this simple one-line function. Is it possible to explain how this function is working and rounding x to nearest block siz

How to store a *signed* 24 bit int into another variable?

I need to encode a 24 bit integer into the end of 32 bit int. (the first byte contains other data, the other three are empty for use by the 24 bit int) I alr

Create a Makefile to compile all .c files in a folder/subfolder and ship the binaries elsewhere

I am currently studying K&R and I would like to create a Makefile in order to automate the compiling process. I have a directory structured as follows : k-r

OS X: How can I get path to Desktop directory on macOS?

How can I get file path to Desktop directory as a string on macOS. I need it to be done in pure C or with some C-level framework.

Reinterpretation of memory

I have been googling a lot on this and have been reading a lot, but still I am not quite understanding it. I hope someone here could cite me a sample with detai

Mergesorting and Removing Duplicates in C (Any language will work)

This is my first question so I apologize in advance if I leave anything out or am ambiguous on an item. Anyway, this is code I got form GeeksForGeeks.org (arr

What is disadvantage of calling sleep() inside mutex lock?

For example: pthread_mutex_lock(); //Do something sleep(1); //causes issues waiting while holding lock pthread_mutex_unlock(); what is the so

How to compare more than 2 strings in C?

I know there is the strcmp but it just let me compare two strings, And I need to compare a lot of them This one doesn't work: if(strcmp (resposta, "S" || "s"

How to initialize only few elements of an array with some values?

Is it possible to assign some values to an array instead of all? To clarify what I want: If I need an array like {1,0,0,0,2,0,0,0,3,0,0,0} I can create it like:

How to calculate a address of a function using base address without using hard coded values

So I'm trying to calculate, using C code the 64 bit virtual address of a function located in ntoskrnl.exe. I have, using C code, determined the base address of

receiving char * from UART of AVR

I want to receive a string(pointer to characters) by UART using ATMEGA16. I burned this code on the kit then I used hyperterminal (realterm) and made a test to

Print character at coordinates in C

I wanted to write a vi-like text editor for Linux in C (just as a personal exercise) and I realized that it would be really useful if I could print a character