c

CPP: avoiding macro expansion of a macro function parameter

what I'd like to do (for logging purposes) is something like this: this code has been written to show my problem, actual code is complex and yes, I have good reasons to use macros even on C++ =) # define LIB_SOME 1 # define LIB_OTHER 2 # define WHERE "at file #a, line #l, function #f: " // (look for syntax hightlighting error at SO x...

C/C++ default argument set as a previous argument

I was unable to find a clear answer to this although that might be because I was not using the proper search terms so please redirect me if that is the case. Is it possible to use previous arguments in a functions parameter list as the default value for later arguments in the parameter list? For instance, void f( int a, int b = a, int...

When are variables removed from memory in C++?

I've been using C++ for a bit now. I'm just never sure how the memory management works, so here it goes: I'm first of all unsure how memory is unallocated in a function, ex: int addTwo(int num) { int temp = 2; num += temp; return num; } So in this example, would temp be removed from memory after the function ends? If not,...

How to unpickle from C code

I have a python code computing a matrix, and I would like to use this matrix (or array, or list) from C code. I wanted to pickle the matrix from the python code, and unpickle it from c code, but I could not find documentation or example on how to do this. I found something about marshalling data, but nothing about unpickling from C. Edi...

Getting the size in bytes or in chars of a member of a struct or union in C/C++?

Let's say that I want to get the size in bytes or in chars for the name field from: struct record { int id; TCHAR name [50]; }; sizeof(record.name) does not work. ...

How to resolve linking error for GetSystemMetrics()?

I'm attempting to use the following to get the height & width of the main display: #include <winuser.h> size_t width = (size_t)GetSystemMetrics(SM_CXBORDER); size_t height = (size_t)GetSystemMetrics(SM_CYBORDER); However, it's failing on an unresolved externals link error (LNK1120). I've tried linking to user32.lib (as documented here...

Compiled C dll can't set pointer when called from ASP.NET App

I've got a 3rd party C application that's compiled to a non-.NET non-COM DLL. It has one simple function declared like so: Declare Function CapiTaxRoutine Lib "taxcommono.dll" (ByVal sInData As String, ByVal OutputData As String, ByVal intINPutLength As Long) As Integer If I place the taxcommono.dll in my path (C:\Windows\System32 is...

Why can I assign structs but not compare them

Even though I am a long time C programmer, I only recently learned that one can directly assign structure variables to one another instead of using memcpy: struct MyStruct a,b; ... a = b; /* implicit memcpy */ Though this feels a bit "high-level" for C, it is definitely useful. But why can't I do equality and inequality comparison: i...

Managing redundant typedefs from multiple vendors

What are some of the best ways to manage redundant typedefs used for platform independence from multiple middleware (operating systems, protocol stacks) vendors in the C programming language. e.g.: target.h /* inclusion lock etc */ typedef char CHAR; typedef unsigned char BYTE; typedef unsigned short int WORD; /* ... more of the same ....

Rounding to use for int -> float -> int round trip conversion

I'm writing a set of numeric type conversion functions for a database engine, and I'm concerned about the behavior of converting large integral floating-point values to integer types with greater precision. Take for example converting a 32-bit int to a 32-bit single-precision float. The 23-bit significand of the float yields about 7 dec...

is there a C library for validating XML against a XML schema?

See question. Also any links to example code or example code on how to validate an xml file against multiple schemas would be helpful. EDT: Sorry forgot to mention that this is for LINUX ...

Is there a simple alternative to Readline?

On a project I'm working on, I'm trying to make it accept user commands and provide history with the up arrow. I'm aiming to keep this project free of dependencies, and I don't want to have to require people to also install the readline development files just to compile my project. Does anyone know of a simple drop-in replacement for GNU...

Dynamically loading registry function on Windows 7?

I am dynamically loading several registry API's from the library Advapi32.dll. Under Windows XP and Vista everything is OK. Under Windows 7 I keep getting the error The parameter is incorrect and in some cases (like RegCloseKey) my application crashes. The code I am using is the usual: // RegCreateKeyEx typedef LONG (WINAPI *MyRegCreat...

Named parameters with Python C API?

How can I simulate the following Python function using the Python C API? def foo(bar, baz="something or other"): print bar, baz (i.e., so that it is possible to call it via: >>> foo("hello") hello something or other >>> foo("hello", baz="world!") hello world! >>> foo("hello", "world!") hello, world! ) ...

How important is it to check return values when using the Python C API?

It seems that everytime I call a function that returns a PyObject*, I have to add four lines of error checking. Example: py_fullname = PyObject_CallMethod(os, "path.join", "ss", folder, filename); if (!py_fullname) { Py_DECREF(pygame); Py_DECREF(os); return NULL; } image = PyObject_CallMethodObjArgs(pygame, "image.load", py_...

Display alert with custom button titles on Windows?

Using CoreFoundation, I can display an alert dialog with the following: CFUserNotificationDisplayAlert(0.0, kCFUserNotificationPlainAlertLevel, NULL, NULL, NULL, CFSTR("Alert title"), CFSTR("Yes?), ...

Limiting framerate of programs externally

Trying to find a way to limit the framerate of programs/games externally in a similar fashion to VSync, but to a specified number (instead of screen refresh rate). A perfect example of what I am aiming for can be seen in FRAPS, when recording a video the framerate is limited to the recording rate. The reason is for fast pace games which ...

CUDA : error C2491: 'log1p' : definition of dllimport function not allowed

I am tryint to integrate CUDA in an existing project, in which several libs (DLLs) are created. I started with a very simple kernel that computes a dot product : // dotProd_kernel.cu __global__ void dotProd( double* result, double* vec1, double* vec2) { int i = threadIdx.x; result[i] = vec1[i] * vec2[i]; } This kernel is called ...

What programs use GSS-API? Any decent sample programs?

I thought I wanted to use GSS-API, but now am not so sure, since I'm having a hard time finding good sample code for a trivial client/server pair. Sun has documentation including sample code, but it's written specifically for their GSS API implementation, using a few proprietary functions not in e.g. the GNU GSS-API (and for which it's ...

Linux kernel's list.h

Where can I find the infamous list.h from the linux kernel? I remember seeing it at once point and I can't for the life of me find it again. I'm running a Windows box so it would be great if you can point me out to a nice HTTP site where it's hosted :) Thanks. ...