How to help gcc vectorize C code

I have the following C code. The first part just reads in a matrix of complex numbers from standard in into matrix called M. The interesting part is the second part. #include <stdio.h> #include <complex.h> #include <stdlib.h> #incl...
more »

2017-01-13 17:01 (2) Answers

Default types for 'complex' in C

According the docs I have read C99 and later support float complex, double complex and long double complex as complex types. However this code compiles without warning when using gcc -Wall -Wextra. #include <stdio.h> #include <complex.h>...
more »

2017-01-13 16:01 (2) Answers

C Multiple arrays permutations algorithm

I'm trying to write a program that generates permutations upon a list of words stored into several arrays. For example, my program asks for 2 groups of words like this : words #1: abc def ghi words #2: 123 456 What i'm trying to have is this outp...
more »

2017-01-13 11:01 (1) Answers

Transform Lebesgue curve to Hilbert curve

I map spatial data onto a one dimensional interval. First I use a space filling Lebesgue curve (or Z curve) in order to connect my points. This works and I get the following plot if I use gnuplot: Then I want to transform the Lebesgue curve to a H...
more »

2017-01-12 21:01 (0) Answers

Functions' order in C

Why does my code work ? I am calling the function generateNumber before declaring it, and I haven't set a prototype at the beginning of the file, so normally it shouldn't work, should it ? Here is my code : #include <stdio.h> #include <std...
more »

2017-01-12 20:01 (2) Answers

C char pointer length

This was a quiz (not graded) on Coursera. The question was, what does the following code possibly evaluate to? The correct answers were 127 and 0 (other options were crash, -1, 128. Why does the following code possibly evaluate to 0? I understand why...
more »

2017-01-12 14:01 (3) Answers

Clarification of C Operator Associativity

I'm reading "The C Programming Language" book, and I came across the following line (paraphrasing): "...in expressions like x = f() + g(); f() maybe called before g() or vice versa. C doesn't specify the order in which the operands will be...
more »

2017-01-12 01:01 (3) Answers

C Trying to validate integer

Trying to validate integer but when wrong value type entered an infinite loop of first printf appears. int main(int argc, char *argv[]) { int input; do{ int starCount; printf("Please enter a number:"); scanf("%d",input); do{ ...
more »

2017-01-12 00:01 (1) Answers

How does the stack works?

from what I understood the stack is used in a function to stock all the local variables that are declared. I also understood that the bottom of the stack correspond to the largest address, and the top to the smallest ones. So, let's say I have this...
more »

2017-01-11 18:01 (3) Answers

Check if Structure is empty C

My program is supposed to differenciate given measurements into cycles and then it to a file. The input file looks like this: reading | force | displacement | velocity 1 | 64.69 | 49.67 | 0.002 2 | 64.54 | 49.66 | 0.002 3 ...
more »

2017-01-11 12:01 (0) Answers

Is this a compiler bug?

My nearly microscopic 8051-based embedded system has a debug serial port, and I wrote a simple serial port output function that was working fine until I made a couple minor tweaks in it to reduce its memory footprint. Then the following line, which W...
more »

2017-01-10 19:01 (1) Answers

output different elements from two arrays

I am trying to output different elements from two arrays. So if i have an array A: {9, 0, 1} and B is {0, 8, 1}, I need to output an element which included in the first set, but are not included in the second :9 Can not think how I should compare all...
more »

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

unshare mount namespace not working as expected

When I call the Linux system function unshare(CLONE_NEWNS), it returns 0 indicating success. But, it doesn't seem to work as I was expecting. Specifically when I then add a new mount such as a tmpfs one, it is globally visible. Therefore it is in f...
more »

2017-01-10 05:01 (1) Answers