c

Reserve memory on OS X

Hey, What's the equivalent to Windows's VirtualAlloc in OS X? That is, how can i reserve a contiguous address space without actually commiting it and then commit chunks of it later? Thanks, Alex ...

Where can I start with programmable Hardware?

I've had a desire to learn at least a tiny bit about programming hardware for quite some time now and thought I'd ask here to get some starting points. I am a reasonably accomplished programmer with Delphi and Objective-c experience but have never even listened to a device port / interupt (I dont even know the terminology) let alone pro...

strcpy() return value

A lot of the functions from the standard C library, especially the ones for string manipulation, and most notably strcpy(), share the following prototype: char *the_function (char *destination, ...) The return value of these functions is in fact the same as the provided destination. Why would you waste the return value for something r...

Keep a global variable or recreate a local variable in c?

Hello, I've been programming with Java for Android quite some while now. Since performance is very important for the stuff I am working on I end up just spamming global variables. I guess everyone will come rushing in now and tell me this is the worst style ever, but lets keep it simple. For Android, local variables means garbage collec...

Doubts in converting spherical coordinates

I'm trying to convert spherical coordinates (namely latitude and longitude from a GPS device) into Cartesian coordinates. I'm following this simple conversion derived from the polar coordinates conversion equations. Then I'm calculating the distance between the two point applying the euclidean distance but the value I'm finding is not a...

supplying inputs to stdin programatically line by line ?

I have a test program which prompts for input from user(stdin), and depending on inputs, it asks for other inputs, which also need to be entered. is there a way I can have a script do all this work ? ...

Syntax for pointer to portion of multi-dimensional statically-allocated array

Okay, I have a multi-dimensional array which is statically-allocated. I'd very much like to get a pointer to a portion of it and use that pointer to access the rest of it. Basically, I'd like to be able to do something like this: #include <stdio.h> #include <string.h> #define DIM1 4 #define DIM2 4 #define DIM3 8 #define DIM4 64 static...

C language: structs and character arrays

When I try to printf() the value of data, I get nothing, but if I were to do date = "text" It would work. Anyone know the reason for that? struct aac { char **data; }; int main ( ) { char* value = malloc ( 100 ); strcpy ( value, "test" ); struct aac b; b.data = malloc ( 100 ); cake ( value, &b ); donut ( &...

Only run C preprocessor in cmake?

I'm trying to use cmake to simplify distributing my OpenCL program. I have a kernel file which includes several headers and other source files, and I want to have a single self contained executable. My plan is to have cmake run the C preprocessor on the kernel source, turning the cl file and its includes into a single unit which is easi...

How can I do modeling in reverse by parsing a C program and turning it in to a circuit diagram to be displayed.

How can I do modeling in reverse by parsing a C program and turning it in to a circuit diagram to be displayed. Example Except this is psedocode. ...

What's use of %c in x86_64 inline assembly?

I'm reading KVM source code and confronted with x86_64 inline assembly. In the following code, what's use of "%c"? It it new feature in x86_64 inline assembly? Any reference for new features in x86_64 inline assembly in gcc? Many thanks /* Check if vmlaunch of vmresume is needed */ "cmp $0, %1 \n\t" /* Load guest registers....

C101--string vs. char:

AFunc changes what was sent to it, and the printf() outputs the changes: void AFunc ( char *myStr, int *myNum ) { *myStr = 's'; *myNum = 9; } int main ( int argc, char *argv[] ) { char someString = 'm'; int n = 6; AFunc(&someString, &n); printf("%c" "%d", someString, n); } But what if the string was more than o...

Variadic macros with zero arguments, and commas

Consider this macro: #define MAKE_TEMPLATE(...) template <typename T, __VA_ARGS__ > When used with zero arguments it produces bad code since the compiler expects an identifier after the comma. Actually, VC's preprocessor is smart enough to remove the comma, but GCC's isn't. Since macros can't be overloaded, it seems like it takes a se...

analysis of core file

hi I'm using Linux redhat 3, can someone explain how is that possible that i am able to analyze with gdb , a core dump generated in Linux redhat 5 ? not that i complaint :) but i need to be sure this will always work... ? EDIT: the shared libraries are the same version, so no worries about that, they are placed in a shaerd storage ...

Memory allocation

Hi, I am experimenting with the c-language right at the moment, yet i have some trouble with memory allocation. After some time i have to restart my computer because my memory runs full. Is there a way to let the compiler tell me which arrays do not get deallocated after the program has run? Thx for answers ...

c-language basics

int main() { double i=4; printf("%d",i); return 0; } can anybody tell why does this program gives output as 0. ...

How to programmatically get the address of the heap on Linux

I can get the address of the end of the heap with sbrk(0), but is there any way to programmatically get the address of the start of the heap, other than by parsing the contents of /proc/self/maps? ...

Using python ctypes to call io_submit in Linux

I'm trying to call io_submit using python ctypes. The code I'm writing is supposed to work on both 32 and 64-bit Intel/AMD architectures, but here I'll focus on 64 bits. I have defined the following: def PADDED64(type, name1, name2): return [(name1, type), (name2, type)] def PADDEDptr64(type, name1, name2): return [(name1, ty...

Out of space on NTFS disk after a series of same-sized files creation/deletion

Hi all, I've ran into a really weird problem while working on a large project. I write a bunch of same-size files on a partition (tried both RAM disks and virtual disks created via diskmgmt.msc). When there is not enough free space to fit another file (as reported by GetDiskFreeSpaceExW), I delete one (only one) of the previously create...

Max number of streams in CUDA?

Is there a maximum number of streams that can be created in CUDA? To clarify I mean CUDA streams as in the stream that allows you to execute kernels and memory operations. ...