c

Testing Frameworks for C

After doing some work with Ruby, Rails, and RSpec last summer and I learned to TATFT. Now I can't write code without writing tests first. I'm taking a programming course in C next year, and I would like to learn to write C test-driven. Is it a good idea (or even possible) to do TDD with C? If so, are there any good testing frameworks co...

C/C++ environment initialization

A co-worker just asked me if it was safe to use getenv() in static initializers, that is, before main(). I looked in Stevens, and in the Posix Programmer's Guide, and the best I can find is An array of strings called the enviroment is made available when the process begins. This array is pointed to by the external variable environ,...

Is there a way to find all the functions exposed by a dll

I've been searching for a way to get all the strings that map to function names in a dll. I mean by this all the strings for which you can call GetProcAddress. If you do a hex dump of a dll the symbols (strings) are there but I figure there must me a system call to acquire those names. ...

Type to use to represent a byte in ANSI (C89/90) C?

Is there a standards-complaint method to represent a byte in ANSI (C89/90) C? I know that, most often, a char happens to be a byte, but my understanding is that this is not guaranteed to be the case. Also, there is stdint.h in the C99 standard, but what was used before C99? I'm curious about both 8 bits specifically, and a "byte" (size...

How to portably convert a string into an uncommon integer type?

Some background: If I wanted to use for, for instance, scanf() to convert a string into a standard integer type, like uint16_t, I’d use SCNu16 from <inttypes.h>, like this: #include <stdio.h> #include <inttypes.h> uint16_t x; char *xs = "17"; sscanf(xs, "%" SCNu16, &x); But a more uncommon integer type like pid_t does not have any suc...

Behaviour of printf when printing a %d without supplying variable name.

I've just encountered a weird problem, I'm trying to printf an integer variable, but I forgot to specify the variable name, i.e. printf("%d"); instead of printf("%d", integerName); Surprisingly the program compiles, there is output and it is not random. In fact, it happens to be the very integer I wanted to print in the first place, ...

Environment overrides for Linux linker/loader

Earlier today I asked a question about environ, and one of the more interesting replies suggested that I could gather information using LD_DEBUG. Now I've known about some linker/loader environment variables (such as *LD_PRELOAD*) for awhile, but this one was new to me. Googling, I found a Linux-specific man page discussing environment ...

What's the best way to get started in modern game programming and application programming?

I want to get started game programming in C/C++, or C# with DirectX or OpenGL. I'm not really sure what I want to get started, but a smallish project like a simple engine would be nice to get started with. Additionally, I would like to learn about designing applications in Windows with C#, .NET 3.5, and WPF. Utilizing C# and .NET, I inte...

Testing framework for functional/system testing for C/C++?

For C++, there are lots of good unit test frameworks out there, but I couldn't find a good one for functional testing. With functional testing, I mean stuff which touches the disk, requires the whole application to be in place etc. Point in case: What framework helps with testing things like whether your I/O works? I've got a hand-rolle...

Virtual allocation granularity and page size

Howdy folks, What are the typical values of the virtual allocation granularity and page size on Win64 platforms? That'd be SYSTEM_INFO's dwAllocationGranularity and dwPageSize. On Win32 systems these would be 64k and 4k. I need to know because I've designed a custom allocator based on VirtualAlloc for a Win32 application and wonder if...

Getting Started with C and Objective-C

I am eventually wanting to program in Objective-C to write programs for OS X and possibly the iPhone. I do not have any direct experience with C and I come from a web programming background. I am much more familiar with java syntax than C and Objective C. I am just looking for suggestions on how to get started. It looks like I need t...

Problem with Closing Sockets. Program Halts.

I am having some trouble with this code. The problem is when i Request the Server to send me some data and the client just Disconnects when the server tries to send me data, the application Exists. Here's the lines I think cause the problem int SendBinary(int *byte, int length) { int bytes_sent; bytes_sent = send(connecting_so...

How to make a single static library from multiple static libraries?

Hello everyone, We recently converted a C++ project from Visual Studio 6 to Visual Studio 8. Everything went well until we reached the compilation of a project who put all the static libraries inside one big static library. By default after the conversion between the two version of projects the project didn't do anything (no big static ...

Dictionary like implementation in C/C++ (Update info)

Does anyone have information or example of how to mount the equivalent of a Dictionary (VB6) in C or C++ ? This implementation is used to be passed as a parameter called DLL VB6. My intention is to create a Dictionary in C (win32 using VARIANT/ARRAYs, etc) and pass it to call a VB. So I have to learn how to create this data structure. ...

Make the C preprocessor ignore certain #include directives

Hi folks! I use a parser generator here, that unfortunately insists on putting a #include <some/file.h> at the top of every generated source file. The header has since long been renamed. While it is no problem forcing the compiler (gcc) to use the new header with -include new/header.h, removing the above directive from every generate...

Does floor() return something that's exactly representable?

In C89, floor() returns a double. Is the following guaranteed to work? double d = floor(3.0 + 0.5); int x = (int) d; assert(x == 3); My concern is that the result of floor might not be exactly representable in IEEE 754. So d gets something like 2.99999, and x ends up being 2. For the answer to this question to be yes, all integers ...

Why can I change the values of a const char* variable?

Why does the following code in C work? const char* str = NULL; str = "test"; str = "test2"; Since str is a pointer to a constant character, why are we allowed to assign it different string literals? Further, how can we protect str from being modified? It seems like this could be a problem if, for example, we later assigned str to a ...

for(;true;) different from while(true)?

If my understanding is correct, they do exactly the same thing. Why would anyone use for the "for" variant? Is it just taste? Edit: I suppose I was also thinking of for (;;). ...

Reading Command Line Arguments of Another Process (Win32 C code)

I need to be able to list the command line arguments (if any) passed to other running processes. I have the PIDs already of the running processes on the system, so basically I need to determine the arguments passed to process with given PID XXX. I'm working on a core piece of a Python module for managing processes. The code is written ...

Double quotes in vim/ubuntu?

I apologize profusely for the incredibly newbish question I'm about to ask, but for some reason, my brain's locked up: I'm trying to code in C on gvim on a virtual machine running Ubuntu, but my Hello World throws compiler errors which I suspect has to do with the quotes being different ascii(unicode?) codes than standard quotes. It do...