c

Using pointers to swap int array values.

I am supposed to use pointers to swap ints in an array. It compiles with no errors or warnings and runs but does not swap the ints. Any suggestions would be helpful!!! Here is the tester: #import <stdio.h> void swap( int ary[] ); int main( int argc, char*argv[] ) { int ary[] = { 25, 50 }; printf( "The array values are: %i an...

GUI for a GNU Debugger

Hi, am pretty excited with the GNU Debugger and a GUI called Insight as it has saved me A LOT OF time. Thus I am posting this question/answer for other newbies out there like me having problems with their C code looking for a visual way to see what's going on. I am working on Linux Mint (Ubuntu) btw. ...

How does one keep an int and an array in shared memory in C?

I'm attempting to write a program in which children processes communicate with each other on Linux. These processes are all created from the same program and as such they share code. I need them to have access to two integer variables as well as an integer array. I have no idea how shared memory works and every resource I've searched ...

The reading list for scientific programmer

Hi all, I am working to become a scientific programmer. I have enough background in Math and Stat but rather lacking on programming background. I found it very hard to learn how to use a language for scientific programming because most of the reference for SP are close to trivial. My work involves statistical/financial modelling and ...

poll() c function on windows

Hi there!I want to know if I can use the poll() function on a MinGW development chain. I have CodeBlocks+MinGW. Thanks a lot. ...

syntax error : 'type'

int max(int N, ...){ int* x = &N; x = x + 1; int max = x[1]; for(int k = 1; k < N ; k += 1){ if(x[k] > max) {max = x[k];} } return max; } void main(){ //printf("%d", max(3)); } I've tried compiling the above code from an key solution, but Im getting the error syntax error : 'type' What's going on... ...

Which is faster, writing raw data to a drive, or writing to a file?

I need to write data into drive. I have two options: write raw sectors.(_write(handle, pBuffer, size);) write into a file (fwrite(pBuffer, size, count, pFile);) Which way is faster? I expected the raw sector writing function, _write, to be more efficient. However, my test result failed! fwrite is faster. _write costs longer time. I'v...

What would the activation record look like for the following code?

int test (int integer ){ int results =0 ; results = 10 - integer; printf("%d \n", &integer); return results; } void main(){ printf("%d \n", test(1)); } ...

Reverse of strcat

I know that strcat (dest, src) appends src to dest, and returns dest. Now, if I want to append dest, to src. i.e. insert string "src" before dest, is their any way to do that? I tried using strcat something like dest = strcat (dest, src); but could not make it work. PS: I am trying out a few options. As this this solution is needed ...

what does this pointer do?

char* p = "hello world"; programmers usually assigns the address of an variable to a pointer. But in the above case, where is the pointer pointing to? and what in the world is int x =42; int* p= &x; int ** r = &p; ...

unsigned int32 linux - not supported

I want to use a unsigned int32, using gcc 4.3.3 on Ubuntu 9.04. However, when I declare this: unsigned int32 dev_number; I get an compile error: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘dev_number’ Any suggestions? ...

Generating random numbers from -n to n in C

I want to generate random numbers from -n to n excluding 0. Can someone provide me the code in C? How to exclude 0? ...

What does %c mean in GCC inline assembly code?

I am trying to understand this inline assembly code which comes from _hypercall0 here. asm volatile ("call hypercall_page+%c[offset]" \ : "=r" (__res) \ : [offset] "i" (__HYPERVISOR_##name * sizeof(hypercall_page[0])) \ : "memory", "edi", "esi", "edx", "ecx", "ebx", "eax") I am having trouble finding informatio...

How to read TCP window size with windows sockets?

Right now im working on a light cliente/server application written in C to check some problems with many computers sending data with TCP to a server through a switch. I need to read some of the flow control variables, like for example the window size, number of retransmitted packets, etc. In linux i do it with getsockopt, method i've...

freopen: reverting back to original stream

Hello, I needed to forward stdout to different files to separate some prints produced and the reverting back to normal stdout. I used freopen to switch to the file in this way: char name[80]; memset(name, 0, 80); strcpy(name, "./scripts/asm/"); strcat(name, m_func->m_name->m_value); strcat(name, ".shasm"); freopen(name, "w", stdout); ...

C/C++ compiler feedback optimization

Has anyone seen any real world numbers for different programs which are using the feedback optimization that C/C++ compilres offer to support the branch prediction, cache preloading functions etc. I searched for it and amazingly not even the popular interpreter development groups seem to have checked the effect. And increasing ruby,py...

What is the smallest exact representation of 1/(2^x) that can be represented in the C programming language?

What is the smallest exact representation of 1/(2^x) that can be represented in the C programming language? ...

Fast 4x4 Matrix Multiplication in C

I am trying to find an optimized C or Assembler implementation of a function that multiplies two 4x4 matrices with each other. The platform is an ARM6 or ARM7 based iPhone or iPod. Currently, I am using a fairly standard approach - just a little loop-unrolled. #define O(y,x) (y + (x<<2)) static inline void Matrix4x4MultiplyBy4x4 (flo...

"static const" vs "#define" in c

Which one is better to use among the below statements in c: static const int var=5; or #define var 5 ...

How to handle EINTR (interrupted System Call)

Hi, My user-space application sometimes blocks after receiving an EINTR-Signal, somehow. What I recorded with strace: time(NULL) = 1257343042 time(NULL) = 1257343042 rt_sigreturn(0xbff07be4) = -1 EINTR (Interrupted system call) --- SIGALRM (Alarm clock) @ 0 (0...