c

Can someone explain Quake3's 'hunk'?

Hi, I've read through the source code, and tried to research it online but i am hitting a brick wall in terms of fully understanding it. By fully i mean, how does it differ from the zone allocation? Is the "zone's" used for small memory and the "hunk" for larger stuff like models etc.? Thanks ...

Learning C properly: yes or no?

My primary language is PHP, but I have done some (not very much) programming in other languages. I've written 2 modules for Apache in C. I wrote them in C because this was one of the things where performance did matter. (generating projected maps of the world on the fly and output to .png). These modules work, and that's as far as I ca...

Objective-C Singleton instance as a static?

In Apple's documentation for their example of a Singleton, and I do understand there's more than one way to skin a cat -- but why do they bother ensuring the instance is registered as static? Take from: http://developer.apple.com/documentation/Cocoa/Conceptual/CocoaFundamentals/CocoaObjects/chapter_3_section_10.html I'm referring to: ...

What alternative environments exist for building projects?

I was looking at the Linux From Scratch project awhile ago and was sort of disapointed that you needed an existing copy of Linux on your machine to build it. I know that Linux is very easy to obtain, install, etc. but I was hoping to build the LFS project outside of the modern operating systems (Unix/Linux/OS-X/Windows/Etc.) and in some...

Why is runtime library a compiler option rather than a linker option?

I'm trying to build a C/C++ static library using visual studio 2005. Since the selection of the runtime library is a compile option, I am forced to build four variations of my library, one for each variation of the runtime library: /MT - static runtime library /MD - DLL runtime library /MTd - debug static runtime library /MDd - debu...

Build OnetwoThree linked list with minimum assignment operators

I came across this problem while preparing for an interview and curious to know the diffrent ways it can be written. I found this at http://cslibrary.stanford.edu/103/ and have given the problem as it is. here is a code to build the list {1,2,3} struct node* BuildOneTwoThree() { struct node* head = NULL; struct node* second = N...

Is this a reasonable use of the ternary operator?

Are there any understanding / maintainability issues that result from code like inVar1 == 0 ? NULL : v.push_back(inVar1); inVar2 == 0 ? NULL : v.push_back(inVar2); and so forth. The possibly confusing idea is using the ternary operator for program flow rather than variable assignment, which is the usual explanation. I haven't seen c...

fopen in C on solaris

I've been trying to get this code to work for hours! All I need to do is open a file to see if it is real and readable. I'm new to C so I'm sure there is something stupid I'm missing. Here is the code (shorthand, but copied): #include <stdio.h> main() { char fpath[200]; char file = "/test/file.this"; sprintf(fpath,"~cs43...

How to read in numbers as command arguments? *update*

I am supposed to produce a program for my computer science class that reads two integers and outputs the product, sum, etc. for the two integers. How can make it where the program reads any two integers input before the program is run? The output is supposed to look like this, with x and y being any variables typed in(we are using Cygwin...

How to fix "assignment makes integer without a cast" **Update**

Okay here's the program I have typed up(stdio.h is included also): /* function main begins program execution */ int main (int argc, char *argv[]) { int x; /*first number input*/ int y; /*second number input*/ int sum; /* variable in which sum will be stored */ int product; /* variable in which product will be stored */ ...

C/C++ check if one bit is set in, i.e. int variable

int temp = 0x5E; // in binary 0b1011110. Is there such a way to check if bit 3 in temp is 1 or 0 without bit shifting and masking. Just want to know if there is some built in function for this, or am I forced to write one myself. ...

How can I simulate OO-style polymorphism in C ?

Is there a way to write OO-like code in the C programming language? See also: http://stackoverflow.com/questions/351733/can-you-write-object-oriented-code-in-c http://stackoverflow.com/questions/415452/object-orientation-in-c Found by searching on "[c] oo". ...

Why does printf() output -1 for large integers?

I'm reading the second edition of K&R book and one of the exercises requires printing all maximum integer values defined in limits.h header. However, this... printf("unsigned int: 0 to %d\n", UINT_MAX); ... outputs the following: unsigned int: 0 to -1 How come I get -1? Anyone could explain this behaviour? I'm using Digital Mars C...

make and alternatives, pros and cons on windows platform

I'm looking for a make platform. I've read a little about gnu make, and that its got some issues on windows platforms (from slash/backslash, to shell determination ... ) so I would like to hear what are my alternatives to it ? If it matters, i'm doing fortran development combined with (very)little c on small sized projects (50k lines ma...

finding center of 2D triangle

(Yes, unfortunately, this is a homework question) I've been given a struct for a 2D triangle with x and y coordinates, a rotation variable, and so on. From the point created by those x and y coordinates, I am supposed to draw a triangle around the point and rotate it appropriately using the rotation variable. I'm familiar with drawing...

Automatically replacing variables with #defines

Hi guys, I've got a tricky problem that I need some help with. Currently, I have a file with about 100 #defines in it, from 1-100, and each with a unique string value. Now I'm trying to print this value, but instead of the value, I want to print what the #define is. For example: #define FIRST_VALUE 1 var = FIRST_VALUE; printf("%s", va...

LINUX: Is it possible to write a working program that does not rely on the libc library?

I wonder if I could write a program in the C-programming language that is executable, albeit not using a single library call, e.g. not even exit()? If so, it obviously wouldn't depend on libraries (libc, ld-linux) at all. ...

Will Garbage Collected C be Faster Than C++?

I had been wondering for quite some time on how to manager memory in my next project. Which is writing a DSL in C/C++. It can be done in any of the three ways. Reference counted C or C++. Garbage collected C. In C++, copying class and structures from stack to stack and managing strings separately with some kind of GC. The community ...

Which embedded database capable of 100 million records has the best C API

I'm looking for a cross-platform database engine that can handle databases up hundreds of millions of records without severe degradation in query performance. It needs to have a C or C++ API which will allow easy, fast construction of records and parsing returned data. Highly discouraged are products where data has to be translated to a...

How does memchr() work under the hood?

Background: I'm trying to create a pure D language implementation of functionality that's roughly equivalent to C's memchr but uses arrays and indices instead of pointers. The reason is so that std.string will work with compile time function evaluation. For those of you unfamiliar w/ D, functions can be evaluated at compile time if ce...