c

DPPS on older version GCC

Hei! I need to optimize some matrix multiplication code in c, and I'm doing it using SSE vector instructions. I also found that there exists SSE4.1 that already has instruction for dot-product, dpps. The problem is that on machine this software is supposed to work there is an old version of gcc installed (4.1.2), which has no support f...

how to integrate two different processes together using two different programs in c language

create two process which communicate using shared memory segment. The first process finds list of all processes on the system with their name, process id, number of files opened and total time running and creates a linked list containing this data about every process running in the shared memory. The second process reads this linked list...

Problems with malloc on OS X

Hi there, I have written a some C code running on OS X 10.6, which happens to be slow so I am using valgrind to check for memory leaks etc. One of the things I have noticed whilst doing this: If I allocate memory to a 2D array like this: double** matrix = NULL; allocate2D(matrix, 2, 2); void allocate2D(double** matrix, int nrows, int...

What is wrong with this linked list delete tail node function?

I have written this function to delete the last node of a singly linked list. The problem is, it is able to delete all the nodes except the first/starting node. What is missing from this code snippet? Please answer my particular problem. #include <stdio.h> #include <stdlib.h> struct Node { char CharContent; struct Node *...

Integer overflow and undefined behavior.

There are many questions about detection of the integer overflow BEFORE the actual addition/substraction because of possible undefined behavior. So, my question is Why it will produce this undefined behavior in the first place? I can think of 2 causes: 1) A processor that generates exception in this case. Sure, it can be toggled off, ...

Is K&R teaching bad readability?

Hello. It has been a while since I looked at C (still learning) and I just got back into the K&R book. I just had a go to Exercise 5-3 (p107). Write a pointer version of the function strcat that we showed in Chapter 2: strcat(s,t) copies the string t to the end of s. I came up with this... void strcat(char *s, char *t); void st...

Functions and pointer to pointers

I have been trying to create a pointer variable in the called function and somehow pass the value pointed by it to the main function. I wrote a few sample programs but it i still seem to be missing something out. and the challenge was to achieve this using pointers to pointers to pointers. Here is the code that I wrote and tested. I thin...

How to use fopen from a C library while Using iPhone SDK...

Hello, I apologize in advance if this has been addressed, but I have not found a specific answer as of yet. First, I am trying to use a C library in an iPhone/Cocoa touch app. It compiles fine as a plain C project and as a plain Foundation project (using X-code). My problems is this: The library uses a dictionary file which is called d...

Core dump file not generated on segmentation fault

Hello, I am trying to debug a segmentation fault caused by my C program using gdb. A core dump file is not automatically generated when i run my program,and i have to run the command ulimit -c unlimited for a core file to be generated on the next run. Why is a core dump file not generated automatically and why do i have to run the ulimi...

Multidimensional array and dllhijacking

I'am currently working on a tool which checks if your apps are vulnerable to dllhijacking. Anyway, there's a section in my code which doesn't look very elegant. Now there are just two sets, but I want to add some more. Is there another way instead of just adding for loops for each set? LPSTR szFileExtWireShark[] = {"airpcap.dll", ".bfr"...

C: Which is faster, accessing global variable or passing a pointer to the function

I am currently rewriting one of my programs. It has a heavily recursive function which solves peg-solitaire: int solve(int draw){ if(finished()) return true; //loop over every possible move (about 76 long long values) //do a move (access the board, which is a long long value) if(solve(int draw + 1)) return true; retu...

In C, there is a way to know when the end of string is reached. Is there a way to know the start when iterating backwards?

Hi. I'm doing K&R Exercise 5-4 (p107). Write the function strend(s,t) , which returns 1 if the string t occurs at the end of the string s, and zero otherwise. I figured the best way to do this was to... increment both pointers to the end count backwards through both strings whilst each char matches return 1 if we had finished c...

Compiling with header files

Why do I have to specifically compile a C source file with: gcc prog.c -lm even when I have already included the specific header file with: #include <math.h> ...

Logic for 9 key keyboard to print qwerty keys

I have a device which has got 9 keys just like an ordinary mobile phone. I want to print normal alphabets like ABCD using these 9 keys exactly the way mobile phones let you do it. This is an embedded system programming project. I am unable to figure out the logic to implement this functionality. I am detecting keys by polling and not...

How to get eflags using only c

I wonder how can I get eflags register content using only c, without any _asm insertions. Is it possible? ...

dendrogram in C compatible with opencv

Hi Is there an implementation of dendrogram in C that can be used with an openCV matrix? If not, is there other implementation of a dendrogram that I can create a distance matrix to? Maybe openCV have anther algorithm that I can use? I've found an scipy-cluster in python which works with numpy. It says that the core is written in C so ...

Pthreads vs. OpenMP

I'm creating a multi-threaded application in C using Linux. I'm unsure whether I should use the POSIX thread API or the OpenMP API. What are the pros & cons of using either? Edit: Could someone clarify whether both APIs create kernel-level or user-level threads? ...

Does the function basename strip away the \n at the end of a path?

Does basename strip away \n at the end of path? For example basename("/home/user/apple\n") would basename return "apple\n" or "apple" without the \n? If basename doesn't get rid of the \n does anyone have any suggestions as to a means of getting rid of the \ ...

How do I print the value of a parameter when the type is not known in C?

How do I know what a particular address pointed by my pointer contains? I want to print the content in this address location? What should I add as a placeholder? ...

Implementation of Gradient (Steepest) Descent

I'm looking for some advice on how to go about implementing Gradient (steepest) Descent in C. I am finding the minimum of f(x)=||Ax-y||^2, with A(n,n) and y(n) given. This is difficult in C (I think) because computing the gradient, Δf(x)=[df/dx(1), ..., df/dx(n)] requires calculating derivatives. I just wanted to throw this at SO to ge...