c

64 bit by 32 bit division

I am looking for a fast way to perform the following divison: Dividend is a signed 64 bit integer. Divisor is a signed 32 bit integer. Quotient should be a signed 64 bit integer, remainder is unnecessary. Low dword of the dividend is zero. I am using only 32 bit data types, since 64 bit ones are poorly supported by the compiler, and ...

Help with if-else in C Program

Possible Duplicate: Whats the condition in C interview question? void main() { if(CONDITION) printf("Hello "); else printf("World"); } Replace CONDITION with such a condition that both the printf statements get executed. You can't have a loop or other things in main() I found t...

What is a portable method to find the maximum value of size_t?

I'd like to know the maximum value of size_t on the system my program is running. My first instinct was to use negative 1, like so: size_t max_size = (size_t)-1; But I'm guessing there's a better way, or a constant defined somewhere. ...

Creating a window manager for Linux

I want to create a simple stacking window manager (in C) for private use, mainly for the purpose of learning and challenging myself. I've looked through twm's source code which has relatively few bells and whistles but it seems very low level since it's not based on a widget toolkit.[1] Would using a toolkit such as GTK+ be preferable? ...

Can't decode a simple ARM function prototype from a dissasembly?

I can't figure out the prototype for this simple function: In stack: Function call: That's what I got so far, and it causes an error. //No idea void CameraDeviceCreate(int one,int two,int* three); There are three registers used (R0,R1,R2) so there should be three arguments. Third one refers to a stack variable (I still don't get...

Is there a way to debug with the visual studio command prompt?

I've got a project that I need to get working with 3 compilers (borland, gnu, and microsoft). It works on 2/3 and now I just need to get it working with microsofts. It seems to crash in places that it works fine with the other compilers, so I'm wondering if there is a way to debug with the command line, maybe to get a stack trace or ge...

Convert a C printf(%c) to C#

Hi, I'm trying to convert this C printf to C# printf("%c%c",(x>>8)&0xff,x&0xff); I've tried something like this: int x = 65535; char[] chars = new char[2]; chars[0] = (char)(x >> 8 & 0xFF); chars[1] = (char)(x & 0xFF); But I'm getting different results. I need to write the result to a file so I'm doing this: tWriter.Write(chars)...

Retrieve the entire rectangle of a scrollable window

I'm trying to retrieve the entire rectangle of a scrollable window using the WIN32 API. I thought that GetClientRect would return what I need, but that function appears to return only the current viewport. Is there a specific function call that returns the entire scrollable region as a RECT or must I call GetScrollRange to calculate th...

Is this code a Circular linkedlist

The following code was been given from our school as a sample for circular linkedlist and told each student to build a own version of circular linkedlist. Now my query is that is the following code is really a circular linkedlist ? // Program of circular linked list #include <stdio.h> #include <malloc.h> struct node { int info; ...

Does the GPC polygon clipper do triangulation?

I was looking at this question Here in regards to this library. However it is still unclear to me if this library can do like glu tesselator does and return a series of triangles which I can then render with OpenGL. If it can do this, how is this done? I'm just not clear on this from reading the docs. So essentially what i'm trying to fi...

How to pass parameters in function that not limit the number of parameters ?

It come across to me that function like printf() have not limited the number of parameters. But when debugging program on Solaris, I noticed it will push at most 5 parameters into stack, common register will be used if there are more than 5 parameters. So what will happen if even common register is not enough in function like printf ?...

Negative array indexes in C?

I was just reading some code and found that the person was using arr[-2] to access the 2nd element before the arr, like so: |a|b|c|d|e|f|g| ^------------ arr[0] ^---------- arr[1] ^---------------- arr[-2] Is that allowed? I know that arr[x] is the same as *(arr + x). So arr[-2] is *(arr - 2), which seems ok. What ...

List environment variables with C in UNIX

Is there a way to enumerate environment variables and retrieve values using C? ...

getaddrinfo inconsistent behavior

I'm using getaddrinfo to start a local server accepting connections only on the localhost: struct addrinfo *res; struct addrinfo hints = {0}; hints.ai_family = AF_UNSPEC; hints.ai_socktype = SOCK_STREAM; hints.ai_protocol = IPPROTO_TCP; getaddrinfo(NULL, portbuf, &hints, &res); This seems to work fine, giving me the IPv6 address ::1 w...

Convert .c to .java

Any tools to convert C code into Java code? I am interested in converting this code into Java: ***************************************************************************/ /* ** UNECM - Decoder for ECM (Error Code Modeler) format. ** Version 1.0 ** Copyright (C) 2002 Neill Corlett ** ** This program is free software; you can redistribut...

string literal in c

Why is the following code illegal? typedef struct{ char a[6]; } point; int main() { point p; p.a = "onetwo"; } Does it have anything to do with the size of the literal? or is it just illegal to assign a string literal to a char array after it's declared? ...

Crossplatform alternative to Winsock?

I basically am looking for a cross platform way to do basic things such as accept connections and send and receive data. What library would work in Linux, Windows and Mac? Thanks ...

Where is dynamic memory allocated?

The question was asked to me in an interview and my answer was "computer memory". But where exactly..? is it the Random Access Memory or the hard drive? ...

first parameter in memset passing array or pointer

Hello, gcc 4.4.4 c89 Pointers are not the same as arrays. But arrays can decay into pointers. I was just using memset which first parameter is a pointer. I would like to initialize my structure array. i.e. struct devices { char name[STRING_SIZE]; size_t profile; char catagory; }; struct devices dev[NUM_DEVICES]; memse...

peterson's solution for critical section problem

#include<stdio.h> #include<sys/types.h> #include<stdlib.h> int turn; int flag[2]; int main(void) { int pid,parent=1; printf("before vfork\n"); if((pid=vfork())<0) { perror("vfork error\n"); return 1; } while(1) { if(pid==0) ...