c

sdl app segfaults on sdl_gl_setattribute

Hi, I'm trying to compile this example and play around with it a bit. I've already corrected the main error the people were having with this example where they would call sdl_gl_setattribute before SDL_Init was called but I'm still getting a segfault right after the first SDL_GL_SetAttribute call. I've ran sdl with opengl apps before on ...

Range of signed char...

Why the range of signed character is -128 to 127 but not -127 to 128 ? ...

GCC inline assembly: constraints

I'm having difficulty understanding the role constraints play in GCC inline assembly (x86). I've read the manual, which explains exactly what each constraint does. The problem is that even though I understand what each constraint does, I have very little understanding of why you would use one constraint over another, or what the implic...

Write regular expression for C numerical literals

My homework is to write a regular expression representing the language of numerical literals from C programming language. I can use l for letter, d for digit, a for +, m for -, and p for point. Assume that there are no limits on the number of consecutive digits in any part of the expression. Some of the examples of valid numerical liter...

Can a C program modify its executable file?

I had a little too much time on my hands and started wondering if I could write a self-modifying program. To that end, I wrote a "Hello World" in C, then used a hex editor to find the location of the "Hello World" string in the compiled executable. Is it possible to modify this program to open itself and overwrite the "Hello World" strin...

Converting a number of bytes into a file size in C

Hello, I want to convert a single number of bytes, into a file size (that has .KB, .MB and .GB). If the number is 0, I don't want to have any unit. If the number is exactly divisible by a multiple of 1024 (not a floating point), then I will print: x . Otherwise, I want to print a floating point with one degree precision. I made some c...

MPI on PBS cluster Hello World

I am using mpiexec to run a couple of hello world executables. They each run, but the number of processes is always 1 where it looks like there should be 4 processes. Does someone understand why? Also I'm not sure why stty is giving me an invalid argument. Thanks! Here is the output: /bin/stty: standard input: invalid argument...

How to send Keystrocks to an aplication in c++ <biginner>

Possible Duplicate: How to send keystrokes to an application in C++ Im trying to make a progam to open acrobat files using adobe acrobat reader and save them in a txt, automaticaly. what i want my program to do is open the pdf send alt + tab //to move to the acrobat tab send alt + f //to open file send down arrow 4 times //to ...

c programming language,pointer

#include<stdio.h> #include<conio.h> main() { char *q[]={"black","white","red"}; printf("%s",*q+3); getch(); return 0; } Code gives output "ck". In this I want to know how *q+3 expression is evaluated. Means first *q is evaluated then 3 is added to what *q points to. In case of integer array it is simple to realise but h...

Does GCC create typedefs for arrays passed to functions?

While debugging some C code with gdb I came across something I've not seen nor heard of before! The compiler (gcc -O0) seems to have created a new type for passing an array of vectors to a function... I think! Have a look at the code and gdb information below: /* The Vector type - nothing unusual */ typedef struct { float x,y,z; } V...

print call stack in C or C++

Is there any way to dump the call stack in a running process in C or C++ every time a certain function is called? What I have in mind is something like this: void foo() { print_stack_trace(); // foo's body return } Where print_stack_trace works similarly to caller in Perl. Or something like this: int main (void) { //...

Win32 listbox not updating immideately after LB_ADDSTRING message

OS: Win7 list box is not updating its region after SendMessage(hwndListData, LB_ADDSTRING, 0, (LPARAM) szListMainBuffer); If mouse cursor is hovered over blank line that should contain text from szListMainBuffer, and clicked, text appears. I have tried using UpdateWindow(), InvalidateRect() functions targeted at hwndListData and pare...

How to fix heap corruption in c/c++?

This is a further question for my previous one here. Is there a general solution for this? ...

Duplicate Visual Studio's memory violation detection on Linux

I developed a command-line (non GUI) C program on Linux using QT Creator, which internally uses gdb as its debugger. When I debugged the program on Windows using Visual Studio, it reported that it was writing outside the bounds of allocated memory (although it did not report the violation at the exact time it occurred, so it was still h...

Malloc in C++ constructor

I have to interface with some C code from C++ class constructor (Intel library) class A{ A{ x = ippiMalloc(); if(x==NULL) ... } } In the constructor malloc function (intel version) is used. If ippiMalloc function do not succeed what is the correct way to handle it. Throw exception? ...

Non-BTree data structure where inserts are done in a sorted manner but i can later remove objects from random places

i want to find an object with O(logN) and also remove with O(log N) - but no go to balanced tree implementation.. any idea's for that? ...

Current right way to do thread programming in Linux

I know that the implementation of threads in the Linux kernel and libc went through big changes in the past. What is the best way to use threads today from C programs? (I don't even know if there is more than one API that I can use -- I just know pthreads) I don't care too much about old kernels and libc versions, but I do care about ma...

Data type promotions during arithmetic operations

main() { if ( -1 < (unsigned char) 1 ) printf("less than"); else printf("NOT less than"); } what is happening? (unsigned char)1 converted to (signed char)1 then: (signed)-1 < (signed)1 thus answer "less than" problem:- in above code change if ( (-1 < (unsigned int) 1 ) answer "NOT less than". So its obvious ...

Imitation of hardware exceptions

Can anyone tell me a code for next function, which raises EXCEPTION_FLT_STACK_CHECK or EXCEPTION_BREAKPOINT, for I could catch them in main func: int _tmain(int argc, _TCHAR* argv[]) { __try { FaultingStack(); // What I need to write in this function??? } __except(GetExceptionCode() == EXCEPTION_FLT_STACK_CHEC...

What files are actually included when compiling

Hi, I have a very large code, a lot of which is legacy code. I want to know which of all these files are taking part in the compilation. The code is written in GNU compilers and mostly in C/C++, but some in other programs too. Any advice will be highly appreciated. Thanks, Moshe. I am compiling under linux with a mix of scripts/...