c

How do you go about compiling a modified version of FreeBSD?

I'm working on an assigned group project at University where we have to re-implement the TCP/IP stack to support some extra stuff (http://discolab.rutgers.edu/mtcp/), and then demonstrate it. The thesis/design we're working from says the original researchers changed the sourcecode for FreeBSD to support the extra bits and bobs. We've g...

Checking lists and running handlers

I find myself writing code that looks like this a lot: set<int> affected_items; while (string code = GetKeyCodeFromSomewhere()) { if (code == "some constant" || code == "some other constant") { affected_items.insert(some_constant_id); } else if (code == "yet another constant" || code == "the constant I didn't mention yet...

I need a standard package to move key,value pairs over a net connection: any tips?

As I hate reinventing the wheel, I wonder if there are any commonly used packaged out there for doing hte simple job of communicating (key,value) pairs of data betweeen two network endpoints (probably TCP/IP is the most likely carrier). I would like something that works in any environment, which for me means Unix/Linux-style socket API ...

Copying content from a hidden or clipped window in XP?

I need to copy the content of a window (BitBlt) which is hidden, to another window. The problem is that once I hide the source window, the device context I got isn't painted anymore. ...

Understanding engine initialization in OpenSSL

I'm trying to set up a basic test of HMAC-SHA-256 hashing but I'm having problems with the engine setup. Ideally I would like to set up only the HMAC-SHA-algorithm but so far I haven't even gotten the general case where load all the algorithms to work. Currently I'm getting segfaults on the row where I try to set the default digests. Al...

Straw Poll - K&R vs BSD

No holy wars please - (ultimately a standardised and consistently-observed house-style on a project always wins out whatever is chosen), but I am genuinely interested in the preferences of people for K&R style formatting: public bool CompareObjects(object first, object second) { if (first == second) { return true; } else...

Why use hex?

Hey! I was looking at this code at http://www.gnu.org/software/m68hc11/examples/primes_8c-source.html I noticed that in some situations they used hex numbers, like in line 134: for (j = 1; val && j <= 0x80; j <<= 1, q++) Now why would they use the 0x80? I am not that good with hex but I found an online hex to decimal and it gave me 1...

How can I compile a Labview CIN in Visual Studio? [RESOLVED]

I am trying to compile a labview CIN using visual studio 2003. I have followed the tutorial located here to the letter, but am getting the following error: Project : error PRJ0019: A tool returned an error code from "Performing Custom Build Step" Does anyone know what is causing this? I tried this link found at an expert's exchange qu...

Memory allocation on Windows C code

I'd like to know which method is recommended on Windows C programming: using malloc or the Win32 HeapAlloc (maybe VirtualAlloc?) function. I've read the MSDN Memory Management Functions article and the MSDN articles regarding malloc and HeapAlloc, but they do not say which one should be used and in what situations. ...

A good reference card / cheat sheet with the basic sort algorithms in C?

I've been looking (without great luck) for the perfect reference card with all the basic sorting algos in C (or maybe in pseudo code). Wikipedia is a terrific source of info but this time I'm looking for something definitely more portable (pocket size if possible) and of course printable. Any suggestion would be much appreciated! ...

What do parentheses in a C variable declaration mean?

Can someone explain what this means? int (*data[2])[2]; ...

Best resource for learning about prefetching a buffer in C on Intel/AMD 64 bit

I am interested in mastering prefetch-related functions such as _mm_prefetch(...) so when I perform operations that loop over arrays, the memory bandwidth is fully utilized. What are the best resources for learning about this? I am doing this work in C using GCC 4 series on an intel linux platform. ...

Using a Single system() Call to Execute Multiple Commands in C

In an information security lab I'm working on, I've been tasked with executing multiple commands with a single call to "system()" (written in C, running on Fedora). What is the syntax that will allow me to execute more than command through system()? (The idea being you could execute arbitrary commands through a program running on a rem...

Which variables should I typecast when doing math operations in C/C++?

For example, when I'm dividing two ints and want a float returned, I superstitiously write something like this: int a = 2, b = 3; float c = (float)a / (float)b; If I do not cast a and b to floats, it'll do integer division and return an int. Similarly, if I want to multiply a signed 8-bit number with an unsigned 8-bit number, I will ...

Examples of good gotos in C or C++

In this thread, we look at examples of good uses of goto in C or C++. It's inspired by an answer which people voted up because they thought I was joking. Summary (label changed from original to make intent even clearer): infinite_loop: // code goes here goto infinite_loop; Why it's better than the alternatives: It's specific...

Making fscanf Ignore Optional Parameter

I am using fscanf to read a file which has lines like Number <-whitespace-> string <-whitespace-> optional_3rd_column I wish to extract the number and string out of each column, but ignore the 3rd_column if it exists Example Data: 12 foo something 03 bar 24 something #randomcomment I would want to extract 12,foo; 03,bar; 24, som...

Why is volatile needed in c?

Why is volatile needed in C? What is it used for? What will it do? ...

Can we output a picture in c?

Hi can we output a .jpg image or .gif image in c? I mean can we print a picture as output with the help of a c program?Aslo can we write a script in C language for html pages as can be written in javascript? Can the browsers operate on it?if not possible is there any plugin for any of the browsers? any example code or links please? ...

Is void** a acceptable type in ANSI-C

I have seen a function whose prototype is : int myfunc(void** ppt) This function is called in a C file as a = myfunc(mystruct **var1); where mystruct is typedef for one of structure we have. This works wihtout any compilation errors in MSVC6.0, But when i compile it with some other C compiler, it gives an error at place where thi...

create std::string from char* in a safe way

I have a char* p, which points to a 0-terminated string. How do I create a C++ string from it in an exception-safe way? Here is an unsafe version: string foo() { char *p = get_string(); string str( p ); free( p ); return str; } An obvious solution would be to try-catch - any easier ways? ...