Multithreading - Raytracer

I've finished my raytracer now but im trying to learn threads to optimize the render time. To represent each pixels of my window im using a int8_t * (4 int8_t / pixel for R/G/B/A). Here is a sample of what im trying to do : Number of threads set : 4...
more »

2017-04-18 23:04 (1) Answers

Unexpected return value from string

I am trying to get just the phone number out of the string passed into getPhoneNumber(char[] str), but for some reason, i get some random character appended to it each time i run the code, please i need help. source code #include <stdio.h> #i...
more »

2017-04-18 18:04 (2) Answers

How does an undefined system call return -1?

I have defined a 'helloworld' system call in my Linux kernel and recompiled it. The code for the system call is: #include<linux/kernel.h> #include<linux/init.h> #include<linux/sched.h> #include<linux/syscalls.h> #include "pro...
more »

2017-04-18 18:04 (1) Answers

how to get argument integer in callee?

I have the following code (caller.c): #include <stdio.h> extern int callee(int); int main(int argc, char *argv[]){ callee(4); return 1; } and (callee.s): .globl callee callee: pop %eax add $4, %eax ret I compile with: gcc -...
more »

2017-04-18 17:04 (1) Answers

C language copying arrays - error in code

I am trying to copy elements from two arrays into a third. I can't understand why it doesn't work. I made sure that the two arrays are filled properly, but for some reason, the actual copying doesn't work- when I print the elements of the arr3, I get...
more »

2017-04-18 16:04 (2) Answers

strcpy working no matter the malloc size?

I'm currently learning C programming and since I'm a python programmer, I'm not entirely sure about the inner workings of C. I just stumbled upon a really weird thing. void test_realloc(){ // So this is the original place allocated for my string ...
more »

2017-04-18 14:04 (4) Answers

When C 'deallocates' local stack variable?

Local variables exists at least (and at most) inside functions. However, what happens to block-scope variables outside block but it the same function, could I keep and use their address? Is this code valid? #include <stdio.h> int main() { ...
more »

2017-04-18 10:04 (1) Answers

Efficient way to split up RGB values in C

I'm writing some software for a 32-bit cortex M0 microcontroller in C and I'm doing alot of manipulations with 32-bit RGB values. They are handled in a 32-bit integer format like 0x00BBRRGG. I want to be able to do math with them without worrying abo...
more »

2017-04-18 05:04 (5) Answers

Typedef struct cannot be cast to pointer

I've seen this question in multiple posts but I have yet to find one that has a good explanation for me. Im trying to create a linked list but the struct nor the functions cant be called without getting the error cannot cast to a pointer. Its really ...
more »

2017-04-18 04:04 (1) Answers

C - Double underscore inside of #define macro

I have done some searching and have consulted a friend of mine, but also want to get the StackExchange's communities input. To preface I'm mainly a HW person who has been slammed into low-level firmware land, so forgive me for anything that seems as ...
more »

2017-04-18 02:04 (1) Answers

Malloc stack overflow

Guys below code works fine until size= 100000. However it gives me stack overflow error after size=200000. How can i fix that ? Is there some way to optimize it ? #include <stdio.h> #include <stdlib.h> #include <malloc.h> #define...
more »

2017-04-17 19:04 (3) Answers

Function pointing to a struct in c

I'm analyzing a bit of code and can't quite seem to grasp some of the workings behind it. struct dplist { dplist_node_t * head; }; struct dplist_node { dplist_node_t * prev, * next; element_t element; }; dplist_t * dpl_create () { dplist_t...
more »

2017-04-17 16:04 (2) Answers

how to print variable in c struct

Please am finding it difficult to print variable b in my struct declaration sum.h #ifndef SUM_H_ #define SUM_H_ typedef struct sumTAG{ int a; int b; }Sum; void addition(); void initialize(); #endif sumtest.c #include "../headers/sum.h"...
more »

2017-04-17 16:04 (1) Answers

c linked list drawing struct to the screen

I have a game that instantiates a new struct every 40 frames and adds it to a linked list. It then loops through the linked list drawing each struct to the screen as a circle using SDL.However, the circles are drawn to the screen and then disappear a...
more »

2017-04-17 16:04 (2) Answers

Unusual behaviour with scanf

I am trying to scan a string, it needs to have a max length of 10. struct Person{ char name[MAX]; float score; date_t dafe; }; //MAX = 11 I am using a menu and when the string entered is less than 10 characters it wor...
more »

2017-04-17 13:04 (1) Answers

Trouble with changing pointer values

So I started learning C today and have had no problems making it through tutorial exercises, but I am finally stuck. I have checked stackoverflow, other reddit posts, and youtube videos. I am trying to created a linked list. Below is my code with det...
more »

2017-04-17 05:04 (2) Answers

placing an interval in an array of pointers

I tried emailing my Professor for help with this and he was not very helpful. given an interval of size 50 starting at x as [x,x+50] (x and x+50 are included), find where to place this interval so that it has the maximum number of elements pointed b...
more »

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

Converting Number to Integer

I need to get a number potentially outside the signed integer range from a string into an integer. I always get the number 0 if the value is outside the signed integer limit. I understand that 0 means the conversion failed. Here is what I've tried:...
more »

2017-04-17 02:04 (2) Answers

malloc in mmapped zone

I am trying to write a program which enables processes to communicate through a shared memory zone. The code I use is below: struct shared { int a; char *f; } int main() { struct shared *f = (struct shared *) mmap(NULL, sizeof(struct ...
more »

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

C Program exits without any output

This had a previous question regarding multi thread issues Here. Now the issue is that the program exits without any input. The program gets the input from a text file given as arguments with executing. It should only contain numbers separated by spa...
more »

2017-04-17 02:04 (2) Answers