c

What does this C idiom mean?

Possible Duplicate: John Carmacks Unusual Fast Inverse Square Root (Quake III) I came across this piece of code a blog recently - it is from the Quake3 Engine. It is meant to calculate the inverse square root fast using the Newton-Rhapson method. float InvSqrt (float x){ float xhalf = 0.5f*x; int i = *(int*)&x; i ...

Learning C: strange code, what does it do?

I'm exploring wxWidgets and at the same time learning C/C++. Often wxWidgets functions expect a wxString rather than a string, therefore wxWidgets provides a macro wxT(yourString) for creating wxStrings. My question concerns the expansion of this macro. If you type wxT("banana") the expanded macro reads L"banana". What meaning does t...

Error Reading from a Pipe

void turtle (int gtot) { int msg; fcntl(gtot,F_SETFL,O_NONBLOCK); read(gtot,&msg,4); gotoxy(12, 21); printf("The value of buffer for turtle is %d",msg); //react to god's message xcoor += msg; msg = 0; sleep(sleep_time); } void god (int gtot ) { char choice, sign; int distance;...

Asterisk space in C - What does the additional white space mean?

I think that *something and * something are different. What does the additional white space do? occurs here -> void * malloc( size_t number_bytes ); ...

Possible to avoid use of global variable in this situation?

I am writing a GTK+ application in C (though the principle here is widely applicable) which contains a GtkComboBox. The GtkComboBox is part of a larger structure returned by another function and packed into the main window. I don't see how I can get the value of what is selected in the GtkComboBox other than by setting a global variable...

How to write a function to clean a memory pool in C

#include<stdio.h> #include<stdlib.h> typedef struct _anyT { int val; } anyT; #define UNITS 10 typedef union _data_block { union _data_block *next; anyT the_type; } data_block; static data_block *free_list = NULL; static void moremem(void) { int i; data_block *more = calloc(sizeof(data_block),UNI...

GetTickCount function

Hi all, I have a question regarding GetTickCount function, I have two calls to this function in my code with several commands between them and the function in both calls returns same count. i.e. var1 = GetTickCount(); code : : var2 = GetTickCount(); var1 and var2 has same values in it. can someone help? ...

What does the following macro do?

Hi, in qemu source code, I have the following macro named offsetof. Can anybody tell me what it does? #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *) 0)->MEMBER) It's used in this manner : offsetof(CPUState, icount_decr.u32) where CPUState is a struct. I think it gives the offset of the member inside a struct, but I'm not sur...

Call C function in Bash script

Related to question 3451993, is it possible to call a function which is internal to subst.c (in the Bash source code) in a Bash script? ...

integer arithmetic on pointers in C

Will the statement below calculate the length of the array???: UART1_BUF[1] = (unsigned char)(lcl_ptr - (unsigned char *)&UART1_BUF[1]); ///////////////////////////////////////////////////////////////////////////////////// unsigned char UART1_BUF[128]; void apple_Build_SetFIDTokenValues(void) /* apple_Build_SetFIDTokenValues - * ...

Why do people define their own offsetof?

Having just seen http://stackoverflow.com/questions/3453063/what-does-the-following-macro-do I gotta ask my own question: why do so many applications' headers define offsetof themselves? Is there some reason why <stddef.h> is not to be relied upon? ...

C program mysql connection

Heey, Can somebody help me out? I'm working on a simple c program that has to connect to my database, then do a query and then close the connection. int main() { MYSQL *conn; conn = mysql_init(NULL); if (conn == NULL) { printf("Error %u %s\n", mysql_errno(conn), mysql_error(conn)); exit(1); } if (...

Polygon in rectangle algorithm?

I have an algorithm which can find if a point is in a given polygon: int CGlEngineFunctions::PointInPoly(int npts, float *xp, float *yp, float x, float y) { int i, j, c = 0; for (i = 0, j = npts-1; i < npts; j = i++) { if ((((yp[i] <= y) && (y < yp[j])) || ((yp[j] <= y) && (y < yp[i]))) && ...

Function abruptly returns when it shouldn't

I am working on an Operating Systems assignment for one of my summer classes. The teacher has provided an object file that provides functions that mimic the behaviour of a disk device driver. We are then to write a file system API that uses the disk device driver in C. I am working on my file system format function named Format() which ...

"C" programmatically clear L2 cache on Linux machines

What would be the programmatic steps written in "C" associated with clearing the L2 cache on a Linux OS machine? /sys/devices/system/cpu/cpu0/cache/index2/size = 6144K x 8CPUs ...

Including header file defined by macro

I need to provide configuration file, which will describe which STL header files to include. I have found that usually it is done by defining a lot of HAVE_XXX_HEADER macros. I wonder if there's something wrong with explicitly providing header name in a macro. Then instead of testing each variant: #if defined(HAVE_TR1_UNORDERED_MAP_HEAD...

How to create a linux user using C/C++?

I would like to build a program which takes a username as parameter and creates the user and its home folder (with some hard-coded specifications like folder, and security checks like username cannot be root or an existing user). My application needs to create users in order to give SSH access. The program will be executed using sudo. ...

Bounding rectangle collision test?

I have complex polygons which I know the minimum x, minimum y, maximum x and maximum y. I also have another rectangle which I know the top left and bottom right vertices. Knowing this information, how can I know if these 2 bounding boxes are colliding? Thanks ...

How can I most effectively share code between C and C# (both Mono and Silverlight)

Our desktop application consists of a Mono/.NET 3.5 back end that communicates via USB with a variety of devices and a Silverlight front end that communicates with the back end via sockets. The firmware for the devices is developed in-house with C. To accelerate our development process and reduce bugs, we would like to share code betwe...

3D Graphics Theory and Code without OpenGL, DirectX, XNA, et al.

I was wondering if there was any tutorial that introduces 3D Graphics theory while showing relevant code, without using OpenGL or DirectX or something. I'm very comfortable with engineering math (I'm an A/V DSP student, so I work with a lot of math all the time). Most of the tutorials I see either show me the same old matrix translatio...