c

strip action code from bison grammar file

Hi Is there any existing tool to strip all the action code from bison grammar files, leaving only the {} around it? ...

Optimal way to initialize varying objects

I have to initialize a lot of different types of objects based on an integer parameter. They all have the same overall initialization methods. At the moment I have the following code #def APPLE 1 #def PEAR 2 switch (t) { case APPLE: newobj = [[FApple alloc] init]; break; case PEAR: newobj = [[FPear] alloc] ini...

error C2440: 'initializing' : cannot convert from 'const wchar_t [9]' to 'LPCSTR'

When I add the following to my code. // Define the input layout D3D10_INPUT_ELEMENT_DESC layout[] = { { L"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0 }, }; UINT numElements = sizeof(layout)/sizeof(layout[0]); I get the following error 1>c:\users\numerical25\desktop\intro todirectx\msdntutor...

What is the cause of these Visual Studio 2010 errors & warnings?

I don't know the cause of these errors I am receiving from Visual Studio 2010. This is the code from my program from line 343 to line 408: int create_den_from_img(char *img_file_name_part, int xlen, int ylen, int zlen ) { IplImage* imgs = 0; char str[80]; unsigned char *data,*imgdata; /* allocating memory */ data = (unsigned...

Signed and unsigned, and how bit extension works in C

unsigned short s; s = 0xffff; int i = s; How does the extension work here? 2 larger order bytes are added, but I'm confused whether 1's or 0's are extended there. This is probably platform dependent so let's focus on what Unix does. Would the two bigger order bytes of the int be filled with 1's or 0's, and why? Basically, does the com...

nested function call faster or not ?

I have this silly argument with a friend and need an authoritative word on it. I have these two snippet and want to know which one is faster ? [A or B] (assuming that compiler does not optimize anything) [A] if ( foo () ); [B] int t = foo (); if ( t ) EDIT : Guys, this might look a silly question to you but I have a hardware ...

sscanf for doubles

This is a simple problem, but I can't see it: char *s = "f 8.649292" ; double d ; sscanf( s, "f %f", printf( "d is %f\n", d ) ; Why is d not containing the double value 8.649292? ...

C equivalent to Perl "system()" or Python subprocess

How do I execute another program from within a C program in Windows 32 - in a similar way as Perl's system() function or Python's sub-process module - such as DEL, REG, or other cmd.exe programs? ...

wonder about some #define tricks

Whlie reading codes of my group project, I come across many DEFINEs, and some of them seems strange. To generalize it, please look at the following 2 examples. Example 1: #define SNPRINTF(dst, fmt, arg...) snprintf(dst, sizeof(dst), fmt, ##arg) what does "##" means in this circumstance? I've tried to delete both of them, and wri...

compile c for fastcgi

I downloaded the developerkit from fastcgi.com. The kit has an examples folder that has a few source files their final, runnable, compiled files. If I put these compiled files in a cgi-bin folder on my apache server (my macbook pro), add the extension fcgi, and go to the url that they are located, they run perfect. I have a test c soru...

c program output

Hello, I am trying some program and confused with the output of the program #include<stdio.h> #define a(x) (x*x) int main() { int i=3,j; j=a(i+1); printf("%d",j); return 0; } I want to know why the program is not giving the output 16(as instead to that i an getting the output 7 for the above program ) i understood the point...

How to name variables which are structs

Hello, i often work on private projects using the WinApi, and as you might know, it has thousands of named and typedefed structs like MEMORY_BASIC_INFORMATION. I will stick to this one in my question, what still is preferred, or better when you want to name a variable of this type. Is there some kind of style guide for this case? For ...

How to tell whether a font is monospace using GTK and Pango?

I have a PangoFontDescription and I want to know whether it describes a monospace font. I have seen the function pango_font_family_is_monospace() in the Pango API documentation but after several hours of puzzling it is still not clear to me what the relationships are between PangoFontFamily, PangoFontMap, PangoFont, PangoFontset, Pango...

How to determine the port numbers for peripheral devices?

I know that peripheral devices such as a hard driver, a floppy driver, etc are controlled by reading/writing certain control registers on their device controllers. I am wondering about the following questions: Is it true that when these peripheral devices are plugged onto the computer, the addresses(port numbers) of their control reg...

Steganography : Encoded audio and video file not being played, getting corrupted. What is the issue

I have made a steganography program to encrypt/Decrypt some text under image audio and video. I used image as bmp(54 byte header) file, audio as wav(44 byte header) file and video as avi(56 byte header) file formats. When I tries to encrypt text under all these file then it gets encrypted successfully and are also getting decrypted co...

Is there a way to have a bit bucket pointer? (C/C++)

Is there a way to have a bit bucket pointer? A lot of IO (specifically input related) system calls return data to a buffer of a specific size. Is there a trick or way to make a sorta bit bucket pointer, so I can accept any amount of data that will be thrown away. Doing something like "char tmp[INT_MAX]" is crazy. The behavior I am looki...

c - fork() and wait()

Hi there, I need to use the fork() and wait() functions to complete an assignment. We are modelling non-deterministic behaviour and need the program to fork() if there is more than one possible transition. In order to try and work out how fork and wait work, I have just made a simple program. I think I understand now how the calls work...

Intel AVX intrinsics: any compatibility library out?

Are there any Intel AVX intrinsics library out? I'm looking for something similar as 'sse2mmx.h' header which fall-backs to MMX intrinsics if SSE2 integer intrinsics are not available on compile time. Thus if I had similar library for AVX I could write optimized code for new hardware which would have almost optimal speed in case AVX exte...

Stopping Backtracking

Is there any way in C/C++ to stop a backtracking algorithm after finding the first solution without exiting the program. I want my function to immediately exit the function,not to quit every level of recurrsion one by one stating return. ...

Designing data structures for an address book in C program?

I want the number of address book items to be variable - not known in advance; I am thinking that using a linked list is the right choice? "The user can enter new person data, or print the data for a given name, the asking data need not be a name but also an address on a telephone number, the program prints the whole information abou...