c

Library / Data Structure to store convex polygon with holes

I need to create a map of a building. The area is a convex polygon that has several non-overlapping convex holes. As a simplification, the area can also be expressed as a rectangle. The holes can also be modelled as rectangles. I first tried to handle it with GEOS, a C++ library that comes with a low level C API. But it seemed that GEOS...

C Unsigned int providing a negative value?

I have an unsigned integer but when i print it out using %d there is sometimes a negative value there? ...

"Error in the program" Can anybody clear this error..? (LINUX FRAMEBUFFER PROGRAM)

#include <unistd.h> #include <stdio.h> #include <fcntl.h> #include <linux/fb.h> #include <sys/mman.h> int main() { int fbfd = 0; struct fb_var_screeninfo vinfo; struct fb_fix_screeninfo finfo; long int screensize = 0; char fbp = 0; int x = 0, y = 0; long int location = 0; // Open the file for reading and writing fbfd = open("/dev/fb0",...

sem_timedwait not supported properly on RedHat Enterprise Linux 5.3 onwards?

Hi, We're seeing odd behaviour on RedHat Enterprise Linux systems with pthreads sem_timedwait. It's only occurring with versions 5.3 onwards. When we create the semaphore on a background thread with sem_init, no error is returned. When we do sem_timedwait, we get an immediate return with errno = 38 (ENOSYS) indicating it's not suppor...

printf slows down my program

I have a small C program to calculate hashes (for hash tables). The code looks quite clean I hope, but there's something unrelated to it that's bugging me. I can easily generate about one million hashes in about 0.2-0.3 seconds (benchmarked with /usr/bin/time). However, when I'm printf()inging them in the for loop, the program slows dow...

overwriting a specific line on a text file?

Hello again,how do I go about overwriting a specific line on a text file in c?. I have values in multiple variables that need to be written onto the file. ...

C programming and error_code variable efficiency

Most code I have ever read uses a int for standard error handling (return values from functions and such). But I am wondering if there is any benefit to be had from using a uint_8 will a compiler -- read: most C compilers on most architectures -- produce instructions using the immediate address mode -- i.e., embed the 1-byte integer into...

long long int in ObjC

Hi All, I am using this NSURLConnection Delegate method - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response { long long rdata = [response expectedContentLength]; NSLog(@"Response Length : %lld", rdata); } its always showing -1 What is the format specifier for long long variable ? T...

Preserving the Execution pipeline

Return types are frequently checked for errors. But, the code that will continue to execute may be specified in different ways. if(!ret) { doNoErrorCode(); } exit(1); or if(ret) { exit(1); } doNoErrorCode(); One way heavyweight CPU's can speculate about the branches taken in near proximity/locality using simple statistics - I...

C macro to transform a SVN revision to an integer

I am looking for a C/C++ macro that can transform a random SVN revision like "$Revision: 9 $" or "$Revision: 9999999 $" into an integer or a string. I know that simple functions exists to achieve this, but I want this to be made at compile time. My wish is to write things like:unsigned int rev = SVN_TO_INT("$Revision$"); ...

LZW Decompression in C

Hi, I have an LZW compressor/decompressor written in C. The initial table consists of ASCII characters and then each now string to be saved into the table consists of a prefix and a character both saved in a list as int. My compression works but my decompression leaves some characters out. The input: <title>Agile</title><body><h1>Agi...

C++ frontend only compiler (convert C++ to C).

I'm currently managing some C++ code that runs on multiple platforms from a single source tree (Win32, Linux, Verifone CC terminals, MBED and even the Nintendo GBA/DS). However I need to build an app targetted at an embedded platform for which there is no C++ compiler (C only). I remmber that many of the early C++ compilers were only fro...

Need help with declarations in C

How do I do the following declaration? int main(int argc, char *argv[]) { char *users[] = {}; char *names[] = {}; openPasswd(users, names); return 0; } void openPasswd(char &users[] = {}, char &names[] = {}){ } I want to populate the 2 char arrays from the function back to the main program. How do I do this? ...

How to read a binary file and display the output as a float in C?

Hi, I'm trying to read 4-byte numbers stored in a binary file, but I don't seem to be getting the correct output. Here's my code: #include <stdio.h> #include <stdlib.h> int main () { int res; FILE *file; float v; //Open file file = fopen("prj3.dat", "rb"); if (!file) { printf("Unable to open file input.dat\n"); } ...

Call Tracing Windows Driver

I wish to be able to record, in real time, the activity of a kernel mode driver (I have the full symbols for it). It's a HID miniclass driver. I wish to record the execution of calls in this driver (stacktraces every time an IRP enters and leaves the driver). Is this possible (maybe with EWT and/or WPT)? ...

How to use protocol buffers ?

Hi , Could someone please help and tell me how to use protocol buffers. Actually I want to exchange data through sockets between a program running on unix and anoother running on windows in order to run simulation studies. The programs that use sockets to exchange data, are written in C/C++ and I would be glad if somneone could help ...

Aspect Oriented Programming (AOP) in C NOT C++ — anyone doing it?

Has anyone seen or written their own framework for doing Aspect Oriented Programming in C? Not C++ -- I've seen already that there's AspectC which is really C++. Involved in embedded software development which requires C only. I am not asking how to do it, only whether someone has done it already. EDIT: Need clarification on one o...

c and objective-c variables

Hi all, Let me see if I can articulate what I'm trying to do... I'll distill it to the core issue. I have an objective-c program and a c callback function. The context is I am using cocos2d and chipmunk physics with the iphone sdk. What I am trying to do is update "score" upon a collision between a bullet and a monster. Everything works...

Find Character String In Binary Data

I have a binary file I've loaded using an NSData object. Is there a way to locate a sequence of characters, 'abcd' for example, within that binary data and return the offset without converting the entire file to a string? Seems like it should be a simple answer, but I'm not sure how to do it. Any ideas? Thanks. UPDATE: I'm doing this o...

Why does this C code print only the first & last node entered?

#include <stdio.h> #include <stdlib.h> typedef struct { char *Name; int grade; int cost; }Hotel; /*This is data element in each node*/ typedef struct hinfo { Hotel h; struct hinfo *next; }Hinfo; /*This is a single node*/ typedef struct { Hinfo *next; /*This is the head pointer of the linked list*/ }HotelHead; void c...