c

What high level languages are easily interfaced with C / C++ ?

I have experience with OCaml. You had to write a stub for every function you wanted to use to convert the types even C int <-> OCaml int. Linking was painful a well. I don't even want to thing about mapping C++ objects. What about other popular languages? Is it always a pain? EDIT: Please avoid duplicates. And state C and C++ interfac...

Is it better to skip OpenGL 2.X and start learning OpenGL 3.X?

Are there huge differences in OpenGL 3.x vs 2.x? Is it waste of time learning OpenGL 2.x or are they both following the same concept? I think i read somewhere that 2.x was state based and that 3.x was not, is that correct? ...

Visual Studio debugging execution path.

I have c code like. FILE * fin = fopen("myfile", "rb"); if (fin == NULL) { printf("file myfile does not exist, closing"); return false; } It works when compiled, but not in debugging mode (stepping trough) where it return false. checking argv[0] is ok and absolute paths are working both ways. ...

C run time stackoverflow

#include <stdio.h> int doHello(){ doHello(); } int main(){ doHello(); printf("\nLeaving Main"); return 0; } When you run the program quits without printing the message "Leaving Main" on the screen. This is a case of Stack Overflow and because of which program is terminating but I don't see any error messages on the co...

cat/Xargs/command VS for/bash/command

The page 38 of the book Linux 101 Hacks suggests: cat url-list.txt | xargs wget –c I usually do: for i in `cat url-list.txt` do wget -c $i done Is there some thing, other than length, where the xargs-technique is superior to the old good for-loop-technique in bash? Added The C source code seems to have only one fork. ...

heap & free homework question

I post this here as a last resort. I'm completely stuck and do not know where to take this. With this question, I'm looking for direction rather than the answer. I've got a home work assignment that actually appears to be a pretty common assignment. The question is here at page 11. This isn't my assignment but it is one I found on Googl...

pointer from integer w/o cast warning when calling lfind

I'm writing a vector in C. The CVectorSearch function uses bsearch if it's sorted, and lfind if it's unsorted. Why am I getting the warning "assignment makes pointer from integer without a cast" when I'm calling lfind? It seems to work fine even when lfind is being used. typedef struct { void *elements; int logicalLength; int a...

What do i need to know about dynamic programming?

Started up solving UVa problems again as a way to pass time (going to the army in 6 weeks). I love writing Java, but end up using C / C++. It's not because IO is faster, no need to box data, more memory or use of unsigned, because its algorithm efficiency that counts. In short i am slowly constructing how to/article/code base for differ...

How to create DRM scheme to protect MP3 files with C++?

Any ideas how I can create a DRM scheme to protect MP3 files using C++ or perhaps some other language? ...

C: Comparison to NULL

Religious arguments aside, in C is ... if (pointer[i] == NULL) ... functionally equivalent to ... if (!pointer[i]) ... ? Does the later resolve quicker due to absence of a comparison ? ...

Finding a bit pattern in a 32bit unsigned integer.

I would describe my question using an example Given a source - 1010 0010, I would like to know how many times (count) the pattern 10 is present in the byte (the source can be of any size 8, 16, 24, or 32 bits). I would like the function which finds the count to be generic. User should be able to give his own pattern viz. 1000, 101 etc...

GCC C++ (ARM) and const pointer to struct field

Let's say there is a simple test code typedef struct { int first; int second; int third; } type_t; #define ADDRESS 0x12345678 #define REGISTER ((type_t*)ADDRESS) const int data = (int)(&REGISTER->second)*2; int main(void) { volatile int data_copy; data_copy = data; while(1) {}; } Which is compiled in Code...

Directed Graph implementation in Objective-C

Before diving in and rolling my own implementation in Objective-C, I'm looking around to try and find an iPhone SDK-compatible directed graph ("digraph") implementation. For the sake of this question, I'll lean on Wikipedia to define the term: Because ensuring the graph is acyclic or otherwise preventing infinite recursion is non-trivi...

Writing a replacement for a C DLL?

I'd like to write a very simple replacement for w3btrv7.dll so I can pass Btrieve API calls to another library (written in .NET and called via COM). Basically, I need to mimic the signature of the BTRCALL function in C. However, I'm not a C programmer... at all. I think I have a pretty good idea of how to write a DLL that exports functio...

How to copy text file to string in C?

I need to copy the contents of a text file to a dinamically-allocated character array. My problem is getting the size of the contents of the file; Google reveals that I need to use fseek and ftell, but for that the file apparently needs to be opened in binary mode, and that gives only garbage. EDIT: I tried opening in text mode, but I g...

Using external libraries in a C program

To me (a beginner in C) it looks like a program can magically access external libraries just by declaring #include "something.h" at the top of a C source file. How is it done? I want to use the POSIX library (unistd.h). I've got the header file itself and a couple of dll's, but I can't link them together and get the compiler (GCC MinGW)...

Identifier Removed (EIDRM) error when sending message with a IPC queue

I'm using an IPC queue to do process synchronization. I always get the EIDRM eror when sending an receiving messages from an IPC queue, but i can see that the queue is there with ipcs. I've been for 2 hours searching but i can't see the error. the following code is a stripped down version that gives me the same error. #define CLAVE ...

How to parallelize Windows message loop and hook callback logic and the Ruby threads it creates?

I'm working on a free, simple, hopefully multi-platform hotkey launcher tool, written in Ruby. Right now I'm struggling with some threading issues of the Windows implementation. The rough proof of concept code shown below already works reliably in my day-to-day use: HotkeyProcessor#process_keypress (footnote 1) gets called by the C cod...

How do I compute the first decimal digit of a division between large numbers?

I have two unsigned long longs X and Y, where X < Y, but both may be very large. I want to compute the first digit past the decimal point of X / Y. For example, if X is 11 and Y is 14, then 11 / 14 is .785…, so the result should be 7. (X * 10) / Y would work, except it produces the wrong result if X * 10 overflows. Conversion to doub...

tracking if a result has already been computed using hash table

My application would perform a large number of matrix operations (e.g., add/ multiply) on dense matrices. I would like to cache unique results in order to avoid duplicate computations. Dense matrix: typdef struct denseMatrix{ int m; int n; double **d; // actual matrix multiplyTable **entry; // key & result } dns; Table...