How to determine ARMv8 features at runtime on iOS?

I am trying to determine when optional ARMv8 cpu features are available on iOS at runtime. On OS X desktops, like i686, x86_64, PPC and PPC64 we can use sysctl. See, for example, PR 3108, SIGILL-free processor capabilities detection on MacOS X. The ...
more »

2017-08-11 16:08 (0) Answers

C socket blocking call

I wonder about the behaviour of socket on blocking and nonblocking actions. What happens to threads blocking on socket when the socket blocking mode changes ? Here is the scenario; thread1(T1) creates a UDP socket and fd = socket(AF_INET , SOCK_DGRA...
more »

2017-08-11 15:08 (4) Answers

Defending "U" suffix after Hex literals

There is some debate between my colleague and I about the U suffix after hexadecimally represented literals. Note, this is not a question about the meaning of this suffix or about what it does. I have found several of those topics here, but I have no...
more »

2017-08-10 20:08 (2) Answers

Wrong array values returning from a function

I am making this program in which my main function calls a function which returns an array after the calculation. I checked already that calculation is right inside the local function. But when I return that array to 'main' function then I only can p...
more »

2017-08-10 17:08 (3) Answers

linux kernel code navigation

I have a question about C code navigation. In C++ or Java it's easy to navigate throught code. For example if there are 3 subsystems (3 classes) DatebaseSubsystem, HardwareSubsystem, ServerSubsystem, and any entity in project use them, I can see all...
more »

2017-08-10 15:08 (0) Answers

Decision making in C - the ? : Operator example

I know how the operator works, but I dont understand how the second case in the code below gives a 1 as a result. #define MIN(a,b) a<b ? a:b int x = MIN(1,2); //case 1, output is 1 int x = MIN(1,1+1); // case 2 Shouldnt the compiler see thi...
more »

2017-08-10 12:08 (3) Answers

atoi() for int128_t type

How can I use argv values with int128_t support? I know about atoi() and family of functions exposed by <cstdlib> but somehow I cannot find one for int128_t fixed width integer. This might be because of the fact that this type isn't backed by e...
more »

2017-08-10 10:08 (5) Answers

Delay output till EOF rather than newline

I am writing a program that copies input to output character by character on Linux terminal. The code is as follows (from Dennis Ritchie's C book) #include <stdio.h> /* copy input to output; 2nd version*/ main() { int c; while ((c = get...
more »

2017-08-09 14:08 (4) Answers

Remove zero entries from an array in C

I have an array of values x = {0,0,1,2,3,0,0,7,8} and I want to remove the zero entries using C. Attempt: I am attempting to loop through each value in the array and check if the entry is not equal to zero. If this condition is true, then I am att...
more »

2017-08-09 12:08 (11) Answers

Address of address of a variable

I was experimenting the behaviors of pointer in C. I wrote the following program: #include <stdio.h> main(){ int a = 1; printf("%p\n", &&a); } I knew that this program would give error. Because an address of address would be ...
more »

2017-08-09 12:08 (5) Answers

How to eliminate unused elements in structures?

Background I am working on a modular architecture for embedded devices where different abstraction layers have to communicate with each others. The current approach is to have plenty of functions, variables and defines mangled with the module name ...
more »

2017-08-09 10:08 (2) Answers

Least Recently Used (LRU) Cache

I know that I can use various container classes in STL but it's an overkill and expensive for this purpose. We have over 1M+ users online and per user we need to maintain 8 unrelated 32-bit data items. The goal is to find if an item exists in the...
more »

2017-08-09 09:08 (6) Answers

c | compare string format

I want to find out if there is any simple option to a string is equal to a format string. for example I want this format .mat[something][something] to be equal to using strcmp to .mat[r1][r2] or .mat[4][5] Is there any option to use regular expressi...
more »

2017-08-08 17:08 (2) Answers

Address of local variable on stack

I wrote a little C code, opened it in GDB, put a breakpoint on line exploit = (long long *)&exploit+2; and run the program. #include<stdio.h> char Shellcode[] = "\x48\xc7\xc0\x01\x00\x00\x00" "\x48\xc7\xc3\x1a\x00\x00\x...
more »

2017-08-08 12:08 (1) Answers

How to retrieve data from a C file efficiently

I have a program that is supposed to retrieve (on start-up) data from a text file. This file may get huge and I was wondering how I could speed up the process and assess its current performance. The code used to retrieve data is as follow: void star...
more »

2017-08-07 22:08 (0) Answers

Strange error using strstr

I am currently implementing a SML Reader for Smart Meters on a STM32F0. Everything works fine, but I have problems using strstr from string.h Current Situation: I have a char Array Data, which contains all Data coming in over USART. It contains Hex...
more »

2017-08-07 18:08 (1) Answers