c

How to swap out a memory block?

How to make a block of memory allocated by malloc() or new: immediately swapped out, or lazily initialized. In fact, I'm trying to reserve an address space. How to accomplish this? PS. How to verify, from the user space, if a memory block is swapped out? ...

Are there any lightweight alternatives to gSOAP?

I've tried using gSOAP for accessing a web service (e.g. using supplied WSDL to generate C stubs and then using them in an app). However, I've found that the generated .c and object files is quite big (several megabytes), which is a problem in embedded environment where I work. Do you know of any simpler SOAP libraries, or do I have to ...

Is it possible to use connection proxies using sockets?

Hi, I need to connect to a server from an environment with a SSL proxy on, is it possible to handle that environment using just sockets? Is it was a no-SSL proxy, would that be possible? Thank you very much. ...

32bit to 64bit inline assembly porting

I have a piece of C++ code (compiled with g++ under a GNU/Linux environment) that load a function pointer (how it does that doesn't matter), pushes some arguments onto the stack with some inline assembly and then calls that function, the code is like : unsigned long stack[] = { 1, 23, 33, 43 }; /* save all the registers and the stack p...

Is there any way to get MSVC to pass structs arguments in registers on x64?

For a function with signature: struct Pair { void *v1, *v2 }; void f(Pair p); compiled on x64, I would like Pair's fields to be passed via register, as if the function was: void f(void *v1, void *v2); Compiling a test with gcc 4.2.1 for x86_64 on OSX 10.6, I can see this is exactly what happens by examining the disassembly. Howeve...

Is there any way a C/C++ program can crash before main()?

Is there any way a program can crash before main()? ...

Why doesn't gcc remove this check of a non-volatile variable?

This question is mostly academic. I ask out of curiosity, not because this poses an actual problem for me. Consider the following incorrect C program. #include <signal.h> #include <stdio.h> static int running = 1; void handler(int u) { running = 0; } int main() { signal(SIGTERM, handler); while (running) ; pr...

Replace the callback for a GtkItem created from a GtkItemFactoryEntry

I'm writing a plugin that's modifying an existing UI. One thing I want to do is change what an existing menu item does. This is all using the Gtk library. The menu item (a GtkItem) is created from a GtkItemFactoryEntry (which is out of my control), and has its current behaviour defined by the callback in the GtkItemFactoryEntry. I ...

Embedded systems code with good unit tests?

I am looking at approaches to Unit Test embedded systems code written in C. At the same time, I am also looking for a good UT framework that I can use. The framework should have a reasonably small number of dependencies. Any great Open-source products that have good UTs? EDIT: Folks, thanks for the answers --I really appreciate the...

pad prefresh to any window instead of stdscr?

Is there a way I can have a pad refresh to any window instead of (presumably) stdscr? I suppose I could temporarily change stdscr every time I want to draw the pad, but that seems a little silly. ...

C Struct initialization : strange way

While reading a code I came across, the following definition and initialization of a struct: // header file struct foo{ char* name; int value; }; //Implementation file struct foo fooElmnt __foo; // some code using fooElmnt struct foo fooElmnt __foo = { .name = "NAME"; .value = some_value; } What does this mean in C and how is...

Timer\Counter in C for rate calculation?

Need a running (moving, rolling) average algorithm to calculate the 5-minute average bits that are passed in. All I have to work with is an accumulative value for the bits that are passed in. For example: I start with 0 bits, 5 minutes later, I have 10 bits, so my average is 10 bits. 5 minutes later, I have 15 bits, so now my averag...

Sending the array of arbitrary length through a socket. Endianness.

Hi everyone, I'm fighting with socket programming now and I've encountered a problem, which I don't know how to solve in a portable way. The task is simple : I need to send the array of 16 bytes over the network, receive it in a client application and parse it. I know, there are functions like htonl, htons and so one to use with uint16 ...

Why does C's "fopen" take a "const char *" as its second argument?

It has always struck me as strange that the C function "fopen" takes a "const char *" as the second argument. I would think it would be easier to both read your code and implement the library's code if there were bit masks defined in stdio.h, like "IO_READ" and such, so you could do things like: FILE* myFile = fopen("file.txt", IO_READ ...

How to make this code compile?

// File: foo.c static int var; void foo() { var++; } // end of file foo.c // File bar.c: static int var; void bar() { var++; } // end of file bar.c // file main.c static int var; void main() { foo(); bar(); printf("%d", var); } // end of file main.c Question: Will the above program compile ? If so what will be the result ? ...

Is there any way to use getaddrinfo() and freeaddrinfo() and still be the program compatible with legacy versions of Windows?

Hi, in the Winsock2 library getaddrinfo() and freeaddrinfo() was only added in Windows XP and on. I know how to replace them in legacy systems, but a conditional use depending on the Windows version won't help. The application won't start in 9x with a message saying that it was linked to a missing export in WS2_32.dll. I'm using MinGW ...

int vs size_t on 64bit

Porting code from 32bit to 64bit. Lots of places with int len = strlen(pstr); These all generate warnings now because strlen() returns size_t which is 64bit and int is still 32bit. So I've been replacing them with size_t len = strlen(pstr); But I just realized that this is not safe, as size_t is unsigned and it can be treated as ...

Writing a telnet client

HI, I have a device that exposes a telnet interface which you can log into using a username and password and then manipulate the working of the device. I have to write a C program that hides the telnet aspect from the client and instead provides an interface for the user to control the device. What would be a good way to proceed. I tr...

check whether mmap'ed address is correct

I'm writing a high-loaded daemon that should be run on the FreeBSD 8.0 and on Linux as well. The main purpose of daemon is to pass files that are requested by their identifier. Identifier is converted into local filename/file size via request to db. And then I use sequential mmap() calls to pass file blocks with send(). However sometime...

Calculating with a variable outside of its bounds in C

If I make a calculation with a variable where an intermediate part of the calculation goes higher then the bounds of that variable type, is there any hazard that some platforms may not like? This is an example of what I'm asking: int a, b; a=30000; b=(a*32000)/32767; I have compiled this, and it does give the correct answer of 29297 ...