c

How do I use a pointer as an offset?

This issue originally came up in a related question of mine where I was having trouble reading some bit of code. The answer turned out to be that this line &((GLushort *)0)[3 * mesh.sBoneBatches.pnBatchOffset[batchNum]] evaluates to be a pointer. And it's used in glDrawElements(GL_TRIANGLES, i32Tris * 3, GL_UNSIGNED_SHORT, &((uns...

How do I get all permutations of xPy in C?

I'd like to calculate all the permutations of size Y of a set of size X. That is if I had (1,2,3) and want all permutations of size 2, 3P2, it would be (1,2) (1,3) (2,1) (2,3) (3,1) (3,2). Both the GSL and C++ STL only provide xPx that I can see. Could someone point me at a C/C++ library which can do this or spell out a fast and memor...

Get the domain name in linux (C programming)

other than getdomainname() is there any way to get the domain name on Linux without having to open and parse files in /etc? Code is appreciated. Thanks ...

C - Pointer to int to get elements in stack

Hello! I wanted to write a standard stack in C but I am not sure if my stk_size() function could work on other platforms except for my 32bit pc. I read that its not good to cast a pointer to int. But what could be a better implementation? I dont want to add a "size"-variable because its redundant in my eyes. Here are some parts of the ...

Ansi C & C++ free e-book source for download

Hello every one, I am failed to find out the free e-books for c & c++ language. ( Specially e-balagurusami if possible ) Actually, I wanted to give this books for trainees for study & revision. Would you help me to find the e-books for this? Thanks in advance for helping me. Sagar. ...

Financial library for C/C++

Do you know of a good open source financial library written in C (preferably) or C++? I already looked at Quantlib, which seems too complicated for me, since I just want some basic computations (total cost of credit, all in-cost credit rate...) Thank you very much! ...

C Network Programming - Winsock

Hey, I have been learning C over the last two weeks, managed to get my head around pointers, arrays and structures. I am looking to do a bit of socket programming on windows and was wondering if anyone has any websites with tutorials and examples or suggest books that teach network programming with winsock? I have tried looking for so...

play a waveform at a certain frequency in SDL callback function

I have a waveform 64 samples long. If the sampling rate is 44100 hz, how can I play(loop) this waveform so that it plays arbitrary frequencies? frequency = samplerate / waveform duration in samples Therefore the frequency should be 689hz(44100/64). If I wanted it to be say, 65.41hz(C-2), I would have to do this: 65.41 = 44100 / x Sol...

Is it possible to use a Unicode "argv"?

Hi, I'm writing a little wrapper for an application that uses files as arguments. The wrapper needs to be in Unicode, so I'm using wchar_t for the characters and strings I have. Now I find myself in a problem, I need to have the arguments of the program in a array of wchar_t's and in a wchar_t string. Is it possible? I'm defining the m...

Creating accessing shared memory in C.

So I have a problem that I don't really know how to go about. I was hoping maybe you could let me know how to deal with it. I need to allocate N number of buffers in shared memory. Each buffer should be initialized to 0. Then I must fork N/2 number of child processes. Each child(i) then writes value (i) into buffer (i), sleeps for one...

What is a better method for packing 4 bytes into 3 than this?

I have an array of values all well within the range 0 - 63, and decided I could pack every 4 bytes into 3 because the values only require 6 bits and I could use the extra 2bits to store the first 2 bits of the next value and so on. Having never done this before I used the switch statement and a nextbit variable (a state machine like dev...

What is the minimum buffer size for sprintf with %g?

The problem is to statically allocate a buffer large enough to fit a printed double, formatted with %g at maximum precision. This seems like a simple enough task, bu I'm having trouble. The best I have come up with (assuming the number to be printed is x) is char buf[1 + DBL_DIG + DBL_DIG + 1 + 1 + 1 + DBL_DIG + 1]; int len = sprintf(...

Copying a directory off a network drive using Objective-C/C

Hi All, I'm trying to figure out a way for this to work: NSString *searchCommand = [[NSString alloc] initWithFormat:@"cp -R /Volumes/Public/DirectoryToCopy* Desktop/"]; const char* system_call = [searchCommand UTF8String]; system(system_call); The system() method does not acknowledge the specific string I am passing in. If I ...

why C, C++, Java does not use one complement?

I heard C, C++, Java uses two complements for binary representation. Why not use 1 complement? Is there any advantage to use 2 complement over 1 complement? ...

Problem forking fork() multiple processes Unix

So I have this function that forks N number of child processes. However it seems to be forking more than specified. Can you tell me what I'm doing wrong? Thanks void forkChildren(int nChildren){ int i; for(i = 1; i <= nChildren; i++){ pid = fork(); if(pid == 0) printf("I'm a child: %d PID: %d\...

How to handle changing data structures on program version update?

I do embedded software, but this isn't really an embedded question, I guess. I don't (can't for technical reasons) use a database like MySQL, just C or C++ structs. Is there a generic philosophy of how to handle changes in the layout of these structs from version to version of the program? Let's take an address book. From program versi...

Why declare a variable or function static in C?

I understand what static does, but not why we use it. Is it just for keeping the abstraction layer? ...

where is rvalue stored in c?

in C, i have this code piece: int a; a = 10 + 5 - 3 I want to ask: where is (10+5-3) stored at? (As far as I know, a is located on stack, how about (10+5-3)? How does this rvalue get calculated?) ...

How to calculate the memory size of a program?

Lets say I have a c program where I use only stack variables, no dynamic variables (malloc, ...) Is it possible to calculate how much memory my program will take during run time? ...

Does stack size grow during runtime?

I wonder if stack size can grow like heap does during runtime? ...