c

determine if an int is a power of 2 or not in a single line

Possible Duplicate: How to check if a number is a power of 2 I made the following code but its not working.The compiler gives an error that for missing ) and expression syntax error.I would also like to know how will the operators proceed?From left to right or right to left? #include <stdio.h> #include <limits.h> #include <ma...

Using files in Check test cases

I need to use a file for one of my tests written using Check. I initially hardcoded the path, which worked fine. However, this didn't work when the code is built outside of the source directory. I came up with the following solution which somewhat works. (I then prefix pathnames with TESTS_DIR) # Set correct directory for test files AS_...

Which file systems support splicing via Linux's splice(2)?

The man page for the splice system call says that splice may fail and set errno to EINVAL if: Target file system doesn't support splicing; neither of the descriptors refers to a pipe; or offset given for non-seekable device Which file systems support splicing? ...

Any library providing common used structures and algorithms for FUSE

Hi, I am going to write a file system prototype by using FUSE. Are there any (additional) well implemented libraries besides FUSE that can provide some common file system optimizing functions like dir cache, journaling, lookup table, atomic ops and etc. It should be better written in C. By the way, I am going to implement it on OSX an...

Why does this Seg Fault?

#include<stdio.h> void main() { char *p="nyks"; p[2]='n'; printf("%s",p); } This crashes with a SEGMENTATION FAULT. Can someone explain why? ...

Do TCP connections get moved to another port after they are opened?

If a TCP socket server listens on port 28081 for incoming connections and then accepts a connection and start receiving data. Is the port that data is coming into still 28081 or does the port get changed. for example what port does the incoming data come to in the pseudo code below? Is it still 28081 or does the OS assign a new port?:...

why different answers?

Below are 2 programs First #include<stdio.h> void main() { int a[5]={1,2,3,4,5}; int *p; p=&a; printf("%u %u",p,p+1); } Second #include<stdio.h> void main() { int a[5]={1,2,3,4,5}; printf("%u %u",&a,&a+1); } Now, in the two programs..I have printed the values of &a using p in first code and directly in th...

Determining whether a readable file descriptor is the read end of a pipe

I would like to use splice to zero-copy data from STDIN_FILENO to a file descriptor (which could be to a regular file, char or block device, FIFO, or anything that can be opened with open). In order to use splice, either the from file descriptor or to file descriptor must be the appropriate end of a pipe, so generally a pipe is created t...

Finding object under mouse

I'm developing a game that basically has its entire terrain made out of AABB boxes. I know the verticies, minimum, and maximum of each box. I also set up my camera like this: glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glRotatef(Camera.rotx,1,0,0); glRotatef(Camera.roty,0,1,0); glRotatef(Camera.rotz,0,0,1); glTranslatef(-Camera.x,-C...

GDB can't access mmap()'d kernel allocated memory?

I'm running into an issue with GDB and some buffers allocated in kernel space. The buffers are allocated by a kernel module that is supposed to allocate contiguous blocks of memory, and then memory mapped into userspace via a mmap() call. GDB, however, can't seem to access these blocks at any time. For example, after hitting a breakpo...

Get OpenCV2.1 to run in windows using eclipse

Hi, I am trying to get OpenCV2.1 to run on my windows machine. Here is what I have done so far: Installed MinGW using MinGW-get-inst Installed Visual Studio C++ 2008 Express Installed OpenCV-2.1.0-win32-vs2008.exe downloaded from OpenCV's website Installed Eclipse Then to test everything, I created a new project, and: Configured Ec...

Omni light in OpenGL?

I want to basically create a light that will make it so that its very bright around the player then gets progressively darker. Sort of like a fire torch. How can I get this effect? I can only seem to get an ambient light? How can it follow the camera? Thanks ...

C getchar vs scanf

I am confused by a piece of code found in a function I am studying: char GetCommand( void ) { char command; do { printf( "Enter command (q=quit, n=new, l=list): " ); scanf( "%c", &command ); Flush(); } while ( (command != 'q') && (command != 'n') && (command != 'l') ); printf( "\...

MinGW Compilation Problem

Hi, I just installed MinGW using the automatic installer MinGW-get-inst that I found on their website. I am using eclipse to write my C++ programs. My code compiles fine, and I get a .exe file. However, when I try to open this executable, I get the error that libgcc_s_dw2-1.dll is missing from my computer. I have located this file under...

Doubt in malloc. C (Linux)

In the following code,what is the meaning of buf = malloc(n * sizeof(char)); is n*sizeof(char) necessary,if yes.. please elaborate. int n; char* buf; fstat(fd, &fs); n = fs.st_size; buf = malloc(n * sizeof(char)); EDIT1 And What if I write (n*sizeof(double)) ...

Dynamic Data Slicing tools for Java and C++

I am looking for dynamic data slicing tools for Java and C++ that can detect both data and control dependencies in the program. I found out JSlice for Java and none for C/C++. Are there any other dynamic data slicing tools available for Java/C++/C ? ...

what is the use of int i()

#include <stdio.h> #define main() main(){printf("hi");}int i() main() {//empty main } what is the use of int i() ...

C header causes errors when included in some files but not others

The title pretty much says it all. The precise error message that seems to be the root of it is: util.h:4: error: expected declaration specifiers or ‘...’ before ‘size_t’ The header in question is: #ifndef UTIL_H #define UTIL_H void print_array(void*, int, size_t, void (*)(void*)); extern void print_int(void*); extern void prin...

Explain C code snippet: preprocessor + printf = ???

The output for this code snippet is %s is a string is a string. Please explain. #include <stdio.h> #define scanf "%s is a string" int main() { printf(scanf, scanf); } ...

In C, is there a cross-platform way to store what a variable might contain for quick reloading of its contents?

The idea is that an application may contain a struct of large arrays that are filled up via a slow external library. So, what if that could be easily stored to a file for fast reference, at least after it has been run once? If it's not possible to be done easily in a cross platform way, is it easy to be done locally 'after a first run'?...