c

Why are nested functions not supported by the C standard?

It doesn't seem like it would be too hard to implement in assembly. gcc also has a flag (-fnested-functions) to enable their use. thanks ...

Changing file permissions in kernel.

I am writing kernel module(C in Linux) and I want to change the permission of the other files in it. any solution? since I am in kernel I can't use chmod syscall and ... thanks for your help This is my Makefile: > obj-m += ca.o > > all: > make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules > > clean: > ...

Clearing output of a terminal program Linux C/C++

I'm interested in clearing the output of a C program produced with printf statements, multiple lines long. My initial guess was to use printf("output1\n"); printf("output2\n"); rewind(stdout); printf("output3\n"); printf("output4\n"); but this produces output1 output2 output3 output4 I was hoping it would produce outpu...

SPOJ ADDREV Wrong Answer

I'm trying to solve the Adding Reversed Numbers problem (ADDREV) at the Sphere Online Judge but my submission keeps coming up wrong answer. I've tried int, unsigned int, long, and unsigned long for my variables and they all work equally well on my computer with some test data (also below) but they all fail the SPOJ. I'm hoping someone ...

load-time ELF relocation

Hi, I am writing a simple user-space ELF loader under Linux (why? for 'fun'). My loader at the moment is quite simple and is designed to load only statically-linked ELF files containing position-independent code. Normally, when a program is loaded by the kernel's ELF loader, it is loaded into its own address space. As such, the data ...

MSVC's _M_X64 Predefined Macro Clarification

The documentation for MSVC's Predefined Macros state "_M_X64 [is] Defined for x64 processors." What does that mean, exactly? Will it be defined: When I'm building for x64 processors, or When I'm building with x64 processors? Specifically, I'm looking for a compiler switch for the former case, not the latter. Will _M_X64 suffice for t...

Is it possible to host the CLR in a C program?

Every example I can find is in C++, but I'm trying to keep my project in C. Is it even possible to host the CLR in a C program? If so, can you point me to an example? ...

PostQuitMessage() Wont close my app???

Im trying to write hello world in win32 but when i close the main window, the app continues to run My window procedure: LRESULT CALLBACK MainWndProc(HWND hWnd, UINT msg, WPARAM wparam, LPARAM lparam) { switch (msg) { case WM_DESTROY: PostQuitMessage(0); return 0; } return DefWindowProc(hWnd, msg, wparam, l...

Function pointer as a member of a C struct

I have a struct as follows, with a pointer to a function called "length" that will return the length of the chars member. typedef struct pstring_t { char * chars; int (* length)(); } PString; I have a function to return the length of the characters from a pointer to a PString: int length(PString * self) { return strlen(se...

Pointer comparison

Does pointers in C and C++ support comparison operators (>, <, etc.) in standard? I want to compare array positions to be precise. ...

"int32 undeclared" gcc error

I'm trying to learn me some C, and have run into what is probably a simple problem. I'm trying to compile some code which contains the following declaration: int32 count; However, this results in an error at compile time: test.c:21: error: ‘int32’ undeclared (first use in this function) Is there a particular compile-time option I ...

C++ for Web Development

Regardless of how hard/long it is, has anybody ever used C or C++ for web development? ...

How can i draw a window content into a bitmap (using Win32 C++)

I need this for some animation effects and i remember there is a window message for doing this. Something like WM_PAINT but it deliveres a device context with the message. But i can't find it anymore on MSDN. ...

runtime error (SIGSEGV)

hi..can anyone tell me whats wrong in the following program that accepts 1 or 2 digit integers untill it encounters the number 42 after which it prints the previously entered numbers??when i upload this to the sphere online judge site it says compilation successful but runtime error (SIGSEGV). #include <stdio.h> int main() { int i; ...

FFT Problem (Returns random results)

Hello, I've got this code, but it keeps returning random frequencies from 0 to about 1050. Please can you help me understand why this is happening. My data length is 1024, sample rate is 8192, and data is a short array filled with input data from the mic. float *iSignal = new float[2048]; float *oSignal = new float[2048]; int pitch =...

Ignore SIGPIPE for a single popen'd FILE*

The code I am looking at is here: http://github.com/andymatuschak/Sparkle/blob/8ea15468b4a8c0487ca7a72f3c9e6ffb708c6af8/SUPipedUnarchiver.m Sparkle is like a plugin. It can be instantiated in a multi-threaded program. Thus I don't want to call signal(SIGPIPE, SIG_IGN) (ie. ignore all SIGPIPE) as who knows what other threads are doing/e...

error C2440: 'function' : cannot convert from 'const IID' to 'DWORD'

While trying to host the CLR, I keep getting this: error C2440: 'function' : cannot convert from 'const IID' to 'DWORD' My code: ICLRRuntimeHost *host = NULL; HRESULT result = CorBindToRuntime(NULL, L"wks", CLSID_CLRRuntimeHost, IID_ICLRRuntimeHost, (PVOID*)&host); This is in C, by the way. Not C++. EDIT: When I compile th...

[C] manually continuing loops

I have a file where each line consists of some words and a number. I'd like to read the file, one line at a time, displaying just the words. Then the program should wait for a key press, and display the number on a certain key, and go on to the next line without displaying the number in the default case. My problem is, the only solution ...

Tricking programs in C

Say I launch a program from the program I make. Is it possible to trick the launched program into thinking the windows directory is in a different place? ...

How do I tell /usr/bin/indent on Mac OS X 10.5 to format my C code K&R style?

On Linux I am used to running indent -kr ... to indent C files. /usr/bin/indent on Mac OS X 10.5 does not support the -kr option. Does anyone have a ~/.indent.pro file that would produce results closest to K&R style? Thanks! ...