What is the use of "-u" option in cat command?

I came across this in man cat (GNU/Linux). The manual simply says -u (ignored) without explaining why. Out of curiosity I searched on Google but it seems no one asked this before. Then I looked at other implementations of cat. I noticed Apple's cat a...
more »

2017-02-16 17:02 (5) Answers

When does underflow occur?

I get into a situation where calculating 1.77e-308/10 triggers an underflow exception, but calculating 1.777e-308/10 does not. This is strange because: Underflow occurs when the true result of a floating point operation is smaller in magnitude...
more »

2017-02-16 15:02 (2) Answers

Why is ioctl call not passed to sys_ioctl?

I have kernel module (4.4.32 kernel) which implements ioctl call by assigning it's ioctl handler to struct file_operations's unlocked_ioctl pointer. All works fine, but I was given program (binary only), compiled for 2.6 or maybe 2.4 kernel which doe...
more »

2017-02-16 13:02 (1) Answers

What exactly is a translation unit in C

The commonly used definition of a translation unit is what comes after preprocessing (header files inclusions, macros, etc along with the source file). This definition is reasonably clear and the C standard, 5.1.1.1, C11, says: A C program need n...
more »

2017-02-16 01:02 (4) Answers

Mitigating memory leaks by forking

This is a really ugly question. I have a C++ program which does the following in a loop: Waits for a JMS message Calculates some data Sends a JMS message in response My program (let's call it "Bob") has a rather severe memory leak. The memory ...
more »

2017-02-15 22:02 (2) Answers

C - Unusual array initialization

I am working on some legacy C code that has this unusual array initialization: uint32_t defsMB40000[REG40000_SIZE] = { #include "modbusDefs40000.h" }; The header file is a list of comma separated numbers and comments. I have never seen this con...
more »

2017-02-15 21:02 (1) Answers

Detaching from shared memory before removing it

When I have several processes going on using a shared memory, and I detach all of them but one. Does it make sense to detach the last process before removing the shared memory with shmctl() (with that process)? If it doesn't make sense, is it possi...
more »

2017-02-15 20:02 (2) Answers

Aligning at the end of a packed struct

Is there anyway to make gcc pad only at the end of a packed structure? I am using a packed structure for space optimization, but also use that struct to compute memory offsets (storing multiple structs in a buffer). Therefore if the total size of my...
more »

2017-02-15 17:02 (1) Answers

character input error in my C program?

I am new to C programming, I have made a simple calculator program in C. The program runs but doesn't work, it works till value for b is entered after then when character input comes it doesn't ask for the input. I don't know why this is happening bu...
more »

2017-02-14 14:02 (2) Answers

Difference in const-ness between gcc and clang

What is the reasoning behind the different error reports between gcc(assignment to read-only) and clang (no error) when compiling the same code? Consider the following C snippet: #include <stdio.h> struct ex { const int x; int y; }; ...
more »

2017-02-14 12:02 (0) Answers

What's the meaning of "int * * k"?

I am beginner of C Programming language. I saw a code on the book: #include<stdio.h> int main(){ int * * k, *a, b=100; a = &b; k = &a; printf("%d\n",* * k); } I don't know the meaning of "int * *k". Is that a integer...
more »

2017-02-14 07:02 (5) Answers

Why there is no error in this program?

--- a.c ---- int i; // external definition ---- main.c ------ int i=0; // external definition int main(void) { i=0; } In both files i is an external defnition in each translation unit and i is used in an expression. That should violate: I...
more »

2017-02-14 01:02 (1) Answers

getting error on running ant command via cmd

Running ant command in cmd.exe and getting the error in change_list_error file as I am trying to build the files on the local system, error is: svn: The path 'C:\aa\aaa\aaaa\simulator' appears to be part of a Subversion 1.7 or greater working cop...
more »

2017-02-13 19:02 (0) Answers

Why can't I find the int value in a binary

I compiled the following program on a 64-bit linux machine: #include <stdio.h> main() { int a = 12345; if (a == 12346) printf ("YES\n"); return; } If I output the binary file using hexdump, I can find the 12346 (which ...
more »

2017-02-13 11:02 (2) Answers

ARM: reading modbus data through UART fails

I am trying to read a register from an RS485 adapter using a UART connection on an ARM board with no success Machines ARM board: CM-T335 - TI AM335x Computer-on-Module http://www.compulab.co.il/products/computer-on-modules/cm-t335/ PC: x86 machine...
more »

2017-02-13 05:02 (1) Answers

32 Bit Signed Integer Addition in C

Here is my program: int main() { int32_t a = 2147483647; int32_t b = -214783648; int32_t s = a + b; printf("%d\n", s); } I expected this to be -1 with no overflow, but my output is this: 1932699999. Does anyone know why? ...
more »

2017-02-13 01:02 (0) Answers

Bi-dimensional array of pointers

I am currently writing a function which uses a bi-dimensional array of pointers to a structure cell. I'll have to update each cell with data read in a file. As I will need to access the various cells, I have to deal with dynamic allocation. But what ...
more »

2017-02-12 15:02 (3) Answers

Does reading from a socket wait or get EOF?

I'm implementing a simple connection between a client and a server in C. In client side, I'm in a loop, reading from a file; every time BUFFER_SIZE bytes and sending it to the server side (didn't upload error handling). //client side bytesNumInput ...
more »

2017-02-12 14:02 (2) Answers