c

Managing resources allocated by client processes

As part of an experiment, I want to write a OpenGL-based UI server for applications, similar to X11 or Quartz in architecture: a core process renders objects into a single viewport, but all graphical objects are being controlled by remote processes. The idea is that the views stability is only dependent on the core process. If a client ...

Partial, or wrapped multiplication - can anyone identify this function ?

I am hoping for insight into what looks like a partial multiplication. #define LOW(x) ((x)&0xffffffff) #define HIGH(x) ((x)>>32) unsigned long long NotMultiply(unsigned long long x, unsigned long long y) { return HIGH(x)*HIGH(y) + LOW(x)*LOW(y); } This function is iterated multiple times, as follows: unsigned long long DoBusy...

Programatically retrieving the absolute path of an OS X command-line app

On Linux, an application can easily get its absolute path by querying /proc/self/exe. On FreeBSD, it's more involved, since you have to build up a sysctl call: int mib[4]; mib[0] = CTL_KERN; mib[1] = KERN_PROC; mib[2] = KERN_PROC_PATHNAME; mib[3] = -1; char buf[1024]; size_t cb = sizeof(buf); sysctl(mib, 4, buf, &cb, NULL, 0); but it...

Smart pointers/safe memory management for C?

Hi, I, and I think many others, have had great success using smart pointers to wrap up unsafe memory operations in C++, using things like RAII, et cetera. However, wrapping memory management is easier to implement when you have destructors, classes, operator overloading, et cetera. For someone writing in raw C99, where could you point ...

How do I force 64 bit integer arithmetic on OS X?

I am trying to force 64 bit long integers on OS X 10.5.6. running on an Apple MacBook Intel Core 2 Duo. Here is my c code: #include<stdio.h> int main() { long a = 2147483647; /*== 2^32 - 1*/ long aplus1; printf("a== %d. sizeof(a) == %d \n", a, sizeof(a)); aplus1 = a+1; printf("aplus1 = %d \n", aplus1); } Compi...

Fast Cross-Platform C/C++ Hashing Library

What's a high performance hashing library that's also cross platform for C/C++. For algorithms such as MD5, SHA1, CRC32 and Adler32. I initially had the impression that Boost had these, but apparently not (yet). The most promising one I have found so far is Crypto++, any other suggestions? http://www.cryptopp.com/ This seems to be qui...

can someone assist in explaining print command in gdb

"Names starting with $ refer to registers (with the values they would have if the program were to return to the stack frame now selected, restoring all registers saved by frames farther in) or else to debugger "convenience" variables (any such name not a known register). Use assignment expressions to give values to convenience variables....

Mark phase misdetection on garbage collection for C

Hello, I've looked at Conservative GC Algorithmic Overview Can a misdetection happen in the 'marking' part? If some data is stored and by coincidence happen to be the same as an address of an allocated memory, will the collector keep the memory ? ...

Getting Started With Programming PICs (or similar products)

How do I get started with programming PICs (or similar products)? Preferably in C. What are some good beginner kits, tutorials, books, etc.? Maybe some little robotic project ideas. ...

Using execl to execute a daemon

I'm writing a program in C on Linux which includes a module that allows a shell command to be executed on a remote machine. The easiest way to actually execute the command would of course be to simply use the system() function, or use popen and then grab the output. However, I chose to use a more low-level approach due to other design...

C/C++ How to tell if a program is already running?

In a Windows environment, I don't want two instances of my program running at the same time. Related Is using a Mutex to prevent multiple instances of the same program from running safe? ...

i want to pop up my own dialog(which save file on server without asking the target path location) instead of adobe's save as dialog.

Can we override the Save As dialog of Adobe Photoshop? How we can override? What will be your approach? Actually I want to pop up my own dialog (which save file on server without asking the target path location) instead of Adobe's Save As dialog. ...

C array address confusion

Say we have the following code: int main(){ int a[3]={1,2,3}; printf(" E: 0x%x\n", a); printf(" &E[2]: 0x%x\n", &a[2]); printf("&E[2]-E: 0x%x\n", &a[2] - a); return 1; } When compiled and run the results are follows: E: 0xbf8231f8 &E[2]: 0xbf823200 &E[2]-E: 0x2 I understand the result of &E[2] whic...

C How to "draw" a Binary Tree to the console

Hi all Im looking for an algorithm( not a library!) i could use to "draw" a binary tree( the tree itself is implemented in C) to the console, so for example a bst with numbers: 2 3 4 5 8 would be shown in the console as : Thanx for all your replyes.... ...

How to cache server connections behind MySQL native UDFs

The MySQL UDF system doesn't provide a good way to have long-term persistent state. I want to be able to write a function that takes the name of a server, and some other arguments, that connects to the server and sends a request, and returns the result. But connecting to the server is a heavyweight operation (much more than just opening...

C With OpenGL and GLFW questions (Mainly a C question)

I am trying to build an application to simulate some basic spheres moving around for this assignment I have got. I am relatively new to C but I have been using .NET and java for some time. The problem that i am facing is that it doesn't look like the data is being assigned to the array outside of the init statement when i actually need...

Mixing C functions in an Objective-C class

I am writing an Objective-C class but is uses an API written in C. This is mostly fine as mixing C calls with Objective-C calls causes few problems. However one of the API call requires a call back method (example): success = CFHostSetClient(host, MyCFHostClientCallBack, &context); Where MyCFHostClientCallBack is a C function defined...

Overflow In c

Hi, I have a doubt When two 16 bit values are added with max values, will there be overflow in the 16 bit machines? I will elaborate unsigned short a; unsigned short b; unsigned long c; c=(unsigned long)(a+b); Talking about 16 bit processers the accumulator will be of 16 bit size. Will there be an overflow in the above statement...

Why does Eclipse CDT say: 'syntax error', but compilation no problem

I am working in existing C code which has a couple of lines with statements similar to this one: struct collect_conn *tc = (struct collect_conn *) ((char *)c - offsetof(struct collect_conn, runicast_conn)); The struct collect_conn goes along the following lines: struct collect_conn { struct runicast_conn runicast_conn; stru...

Is runtime stack kept in data segment of memory?

I'm very curious of the stack memory organization after I experiment what's going on in the background and obviously saw it's matching with tiny knowledge I acquired from books. Just wanted to check if what I've understood is correct. I have a fundamental program -- has 2 functions, first one is foo and the other is main (the entry poin...