c

C libraries for parsing Erlang binaries?

I have an erlang server that will be communicating via tcp sockets with a client written in C. Are there any C libraries for parsing erlang binary terms to C structs? I realize this is not absolutely necessary, but it would be very convenient. ...

Implementing Java's getResponseCode() in C?

If it's any help, there is also a similar class in C#'s WebRequest. Although I do not want it in java or .NET, i am wondering how to implement this in native C/C++ code (for windows). for reference: try { URL url=new URL("http://google.ca"); HttpURLConnection con=(HttpURLConnection)url.openConnection(); con.connect(); int code = con.g...

Is it possible to predict a stack overflow in C on Linux?

There are certain conditions that can cause stack overflows on an x86 Linux system: struct my_big_object[HUGE_NUMBER] on the stack. Walking through it eventually causes SIGSEGV. The alloca() routine (like malloc(), but uses the stack, automatically frees itself, and also blows up with SIGSEGV if it's too big). Update: alloca() isn't f...

Can you nest C preprocessor directives?

For instance, is the following possible: #define definer(x) #define #x? Thanks. ...

Fastest way to clamp a real (fixed/floating point) value?

Hi, Is there a more efficient way to clamp real numbers than using if statements or ternary operators? I want to do this both for doubles and for a 32-bit fixpoint implementation (16.16). I'm not asking for code that can handle both cases; they will be handled in separate functions. Obviously, I can do something like: double clampedA; ...

How can I concatenate upper and lower nibbles stored sequentially in an array?

Hi friends, I have an array which contains a list of nibbles: {0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, ...} I want to combine adjacent nibbles into single bytes by left-shifting the upper nibble and concatenating it with the lower one. The output should look as follows: {0xab, 0xcd, 0xef, ...} How can I accomplish this in C? ...

Difference between "struct foo*" and "foo*" where foo is a struct?

In C, is there a difference between writing "struct foo" instead of just "foo" if foo is a struct? For example: struct sockaddr_in sin; struct sockaddr *sa; // Are these two lines equivalent? sa = (struct sockaddr*)&sin; sa = (sockaddr*)&sin; Thanks /Erik ...

reading 16-bit greyscale TIFF

I'm trying to read a 16-bit greyscale TIFF file (BitsPerSample=16) using a small C program to convert into an array of floating point numbers for further analysis. The pixel data are, according to the header information, in a single strip of 2048x2048 pixels. Encoding is little-endian. With that header information, I was expecting to b...

How to play MP3 files in C?

Hello all, I'm looking for the easiet way to play an MP3 file in C. Either a library I could use and just call the function on the filename, or alternatively something someone's already written that will just run and quit. Thanks! Let me know if I can be any more clear. ...

What parser generator do you recommend

I'm currently shopping for a FOSS parser generator for a project of mine. It has to support either C or C++. I've looked at bison/flex and at boost::spirit. I went from writing my own to spirit to bison to spirit to bison to spirit, each time hit by some feature I found unpleasant. The thing I hate most about bison/flex is that they a...

How to speed up floating-point to integer number conversion?

We're doing a great deal of floating-point to integer number conversions in our project. Basically, something like this for(int i = 0; i < HUGE_NUMBER; i++) int_array[i] = float_array[i]; The default C function which performs the conversion turns out to be quite time consuming. Is there any work around (maybe a hand tuned functi...

How do C and C++ store large objects on the stack?

I am trying to figure out how C and C++ store large objects on the stack. Usually, the stack is the size of an integer, so I don't understand how larger objects are stored there. Do they simply take up multiple stack "slots"? ...

Why does malloc allocate a different number of bytes than requested?

I have this piece of code #include <stdio.h> #include <stdlib.h> #include <stdint.h> #include <string.h> int main(){ void *a, *b; a=malloc(16); b=malloc(16); printf("\n block size (for a): %p-%p : %li",b,a,b-a); a=malloc(1024); b=malloc(1024); printf("\n block size (for a): %p-%p : %li",b,a,b-a); } This shouldn't display the t...

Is C strongly typed?

To quote Wikipedia: Two commonly used languages that support many kinds of implicit conversion are C and C++, and it is sometimes claimed that these are weakly typed languages. However, others argue that these languages place enough restrictions on how operands of different types can be mixed, that the two should be r...

G-mail style form submission on table data

I have table rows of data in html being filled from a CGI application. I want each row to have a check box next to it so I can delete multiple rows, just like in gmail. I figured out the basic text form and was able to send it to the CGI program to delete the row, but I don't want to have to type in the row name to delete a single fil...

How can I detect the operating system in C/C++?

I would like to detect whether the OS I'm compiling on is Windows. Is there a simple macro I can check to verify that? ...

libpcap, pcap_next_ex, and incompatible pointer types

Disclaimer: This is for a homework assignment, but the question is not regarding the assignment, just about general syntax weirdness. I'm trying to use libpcap in the context of a much larger program, but when I try to get the packet header and data for each packet gcc complains that the third parameter to pcap_next_ex is of an incompat...

Is there an open source C visual debugger for windows?

Is there an open source C visual debugger for windows? I have heard about the visual C++ express free edition, but does it have a visual debugger? Thanks. ...

C, HTTP 1.1 and Socket Send troubles

As an addition to my previous post on Creating a web server in pure C, I'm having some trouble with the Sending function. Here's two code snippets: int Send(char *message) { int length, bytes_sent; length = strlen(message); bytes_sent = send(connecting_socket, message, length, 0); return bytes_sent; } ...

Why is it "impossible" to implement garbage collection in C because of weak typing?

I was told by a rather smart person that you cannot implement garbage collection in C because of it's weakly typed. The basic idea seems to be that C gives you too much freedom. He mentioned casting pointers without type checking... I don't really grok the idea. Can someone give me an explanation and possibly a code sample of why this w...