c

big integers with fixed length

I am looking for a library for big integers but with fixed width (128 or 256 would be enough). The reason is I don't want any allocation on the heap. I tried to make them myself but implementing multiplication, division and modulo an efficient way seems to be quite a pain. Does this already exists somewhere ? Thanks ...

How to raise a double value by power of 12?

I have a double which is: double mydouble = 10; and I want 10^12, so 10 * 10 * 10 * 10 * 10 * 10 * 10 * 10 * 10 * 10 * 10 * 10. I tried double newDouble = pow(10, 12); and it returns me in NSLog: pow=-1.991886 makes not much sense... I think pow isn't my friend right? ...

Creating custom message types in win32?

Is there a way to define and send custom message types in Win32, to be caught by your Main message handler? For example, my main message handler captures messages such as WM_PAINT, WM_RESIZE, WM_LBUTTONDOWN etc. Can I create my own WM_DOSOMETHING? If so, how would I send this message? Ah, I actually just discovered this was asked before...

Why is that data structures usually have a size of 2^n ?

Is there a historical reason or something ? I've seen quite a few times something like char foo[256]; or #define BUF_SIZE 1024. Even I do mostly only use 2^n sized buffers, mostly because I think it looks more elegant and that way I don't have to think of a specific number. But I'm not quite sure if that's the reason most people use them...

How to create bitmap from integer array in C / OpenGL

I am trying to move my code from Java to C, and I have encountered a problem while trying to find a function in C that can take an array of ints and create a bitmap from it for OpenGL. In Java, I used bitmap = Bitmap.createBitmap( {int array name} , w, h, Config.RGB_565); Is there a similar function that I can use in C, or a workar...

Extracting bits

In C, I have a 32bit word representing an address (and I have it stored in a unsigned long, hope thats ok). Now from what I gather, part of an address contains the page number and the other part contains the offset. I was wondering how I could extract just the bits that give me the page number. I have already worked out the first 22 mos...

Transparent SQLite Data Compression

I am looking for an existing solution for transparent SQLite 3 zlib compression using a custom VFS implementation and a custom IO methods implementation. Is anyone aware of an existing project that already does that, or will I have to roll my own? I vaguely remember seeing something similar a year ago, but can't find it anymore. ...

Malloc a pointer to a pointer to a structure array by reference

The code below compiles, but immediately crashes for reasons obvious to others, but not to me. I can't seem to get it right, can anyone tell me how to fix this. *array_ref[2] = array[0]; *array_ref[3] = array[1]; It crashes on that part everytime. typedef struct test { char *name; char *last_name; } person; int setName(per...

Library redefines NULL

I'm working with a library that redefines NULL. It causes some problems with other parts of my program. I'm not sure what I can do about it. Any idea? My program's in C++, the library's in C. #ifdef NULL #undef NULL #endif /** * NULL define. */ #define NULL ((void *) 0) Oh, and it produces these errors: Generic.h:67: error: def...

forking a process seems to eat up certain lines of code - Objective-C

Here's a simplified version of my code: - (IBAction)convert:(id)sender { /* these two lines are ignored */ [textbox setStringValue:@"converting"]; [convertButton setEnabled:NO]; pid_t pid; if((pid=fork())==-1) { [log setStringValue:@"couldn't fork a new process."]; converting = 0; [convertBut...

Sound Monitoring in C++/Python

I'm looking for an API (or some information as to where to look/start) that will ultimately allow me to monitor sound being played by the computer. My end goal (well, certain to eventually be a stepping-stone) is an oscilloscope. Where should I begin to look (aside from Google, which has yielded unsatisfactory results) to learn more a...

Can inline function bodies in C reference entities declared later

Lets say i have two inline functions in my header file: inline int foo() { return bar()+2; } inline int bar() { return 3; } can i assume that a C99 compiler will inline "foo" even if 'bar' is declared later? Assuming that no other internal rule like function body to large is triggered. Are implementations of c compilers doing this (p...

Reading characters outside ASCII.

A friend of mine showed me a situation where reading characters produced unexpected behaviour. Reading the character '¤' caused his program to crash. I was able to conclude that '¤' is 164 decimal so it's over the ASCII range. We noticed the behaviour on '¤' but any character >127 seems to show the problem. The question is how would we ...

copying text to a character array from a text file in C?

Hey there, How do I go about copying text inside a text file into a multidimensional character array? supposing the text file( text_file.txt) contained this is the first line this is the second line this is the third line #include <stdio.h> int main(void){ FILE *f; f=fopen("text_file.txt","r"); if (f==NULL){ printf(...

Can every if-else construct be replaced by an equivalent conditional expression?

(I don't have a serious need for this answer, I am just inquisitive.) Can every if-else construct be replaced by an equivalent conditional expression using the conditional operator ?:? ...

Using Sparse to check C code

Does anyone have experience with Sparse? I seem unable to find any documentation, so the warnings and errors it produces are unclear to me. I tried checking the mailing list and man page but there really isn't much in either. For instance, I use INT_MAX in one of my files. This generates an error (undefined identifier) even though I #in...

Why don't win32 API functions have overloads and instead use Ex as suffix?

The win32 API has for example two methods StrFormatByteSize and StrFormatByteSizeEx. Even though both the methods symantically do the same thing and the Ex counter part only offers a new parameter to slightly change the behavior then couldn't they have two overloads of the same function? Is it a limitation of c/c++ or what is the possib...

C: What is the type of &array_name?

What is the type of &a in the following code? char a[100]; myfunc(&a) Is this even valid code? gcc -Wall complains about missing prototype but will otherwise generate code as if myfunc(a) was written. ...

What range of values can integer types store in C++

Can unsigned long int hold a ten digits number (1,000,000,000 - 9,999,999,999) on a 32-bit computer. What is the what is the range of unsigned long int , long int, unsigned int, short int, short unsigned int and int? ...

Handling large integer on C/C++ using Visual C++ 2008

How do I do to handles some big positive integers (like 9,999,999,999) on Visual C++ 2008 on a 32-bit PC. Please give an example on declaring, printf, scanf of these big positive integers. Please consider using 9,999,999,999 in your example. ...