c

Does ANSI C support ‘templates?’

I’m taking a C++ class, and my teacher mentioned in passing that the typename keyword existed in C++ (as opposed to using the class keyword in a template declaration), for backwards compatibility with “C templates.” This blew my mind. I’ve never seen or heard tell of anything like C++’s templates (except, perhaps, the preprocessor… and ...

How to install new units (i mean includes ex: stdio.h) for my C

How to install new units (i mean includes ex: stdio.h) for my C, and how to download more? ...

C: Call free on an automatic variable?

int main() { int x = 0; free(x); } This compiles and appears to be a no-op. What actually happens? is this behavior defined? Thanks! ...

Why doesn't scanf work when using the Win32 ConsoleInput function?

Hi! This is the example code, I'm using these functions for a program, but scanf doesn't work well: It doesn't display my input and accepts the input only after the enter key is pressed twice. this is the code: #include <stdio.h> #include <windows.h> char c[25]; void KeyEventProc(KEY_EVENT_RECORD); void KeyEventProc(KEY_EVENT_RECORD k...

How do I measure the total size of my global variables?

I'm creating a c program that I intend to run on an ARM processor in the near timeframe. I want to measure the amount of memory I'm using with my global variables while ignoring the size of the stack/heap. Is there a way to either get gcc to dump this out at compile time or to retrieve this information from the compiled binary? ...

How do I write a web server in C on linux

I am looking into developing a small (read:rudimentary) web server on a linux platform and I have no idea where to start. What I want it to be able to do is: Listen on a specific port Take HTTP post and get requests Respond appropriately No session management required Has to be in C or C++ Has to run as a service on boot I am famili...

Protecting /etc/passwd and /etc/shadow from concurrent access

How do I protect /etc/passwd and /etc/shadow from concurrent access? I don't see any locking mechanism in pwd.h. I see the manual for pwd_mkdb mentions obtaining a lock, but is it just locking the file for exclusive access? Is there a convention for locking these files if I were to write a utility to modify them directly, or through t...

How to invoke C compiler under gcc

According to my memory the following piece of code should compile fine on C++ but not in C. Only problem is how to test it? It compiled fine with g++ and also with gcc. I'm assuming that g++ is C++ compiler and gcc is C compiler. I've tried it with mingw under Windows. Am I correct? if not then how to compile it using C compiler. int ma...

Why does my application freeze when I copy a large file?

I have an MFC application. It is basically just copying files from one drive to another. When I'm copying large files (more than 1 Gb) and I click on my window, my application freezes, but the copying proceeds in the background. Someone told me that I have to use a worker thread. I used it, but it still freezes. When I'm copying small fi...

what are the platform-name macros called? (e.g., __SVR4)

The pycups-1.9.48 library doesn't build on Mac OS 10.6 unless I remove this ifdef: #ifdef __SVR4 /* * A rudimentary emulation of getline() for systems that dont support it * natively. Since this is used for PPD file reading, it assumes (possibly * falsely) that BUFSIZ is big enough. */ ssize_t getline(char **line, size_t *linelen, ...

How to use correctly CopyFileEx and CopyProgressRoutine functions?

Hi! I made an application which copies files, usually large files. I want to show the progress of the copying, but i can't it bring to work. Can someone tell me what i am doing wrong? Now it works very interesting. The % goes to 49% than, back to 0, and then to 40, then again back to 0 and then back 35, and this goes on, untill it copi...

Is there any reason a .Net windows programmer needs to learn C or C++ anymore?

Can someone describe what advantages a C or C++ programmer would have over a .Net programming when developing for Windows? ...

What are the differences between .so and .dylib on osx?

.dylib is the dynamic library extension on OSX, but it's never been clear to me when I can't / shouldn't use a traditional unix .so shared object. Some of the questions I have: At a conceptual level, what are the main differences between .so and .dylib? When can/should I use one over the other? Compilation tricks & tips (For example,...

image compression using Huffman Coding

Hello, I have some difficulties in my project. I got the RGB values from a 256x256 bmp image. however, i don't know how to continue by using the huffman coding to compress those RGB value. Can anyone help me? Thanks for your help. #include <stdio.h> #include <stdlib.h> #include <math.h> /*-------PROTOTYPES-------*/ long getImageInfo(FI...

How to turn off gcc compiler optimization to enable buffer overflow

Hello - I'm working on a hw problem that requires disabling compiler optimization protection for it to work. I'm using gcc 4.4.1 on ubuntu linux, but can't figure out which flags are are the right ones. I realize it's architecture dependant - my machine runs w/ 32-bit Intel processor. Thanks. ...

Counting clusters in a hash set

I'm trying to debug a hashset implementation (for a school assignment). Collisions are being managed via linear probing, and I need to count the number of clusters of a given size for the debug routine. I worked this up: // really just hoping that a 50+ cluster doesn't occur int clusters[50]; int count = 0; for (int i=0; i < hashset->di...

Difference between fflush and fsync

I thought fsync() does fflush() internally so using fsync() on a stream is OK. But i am getting unexpected result when executed under network I/O. My code snippet: FILE* fp = fopen(file,"wb"); /* multiple fputs() call like: */ fputs(buf, fp); ... ... fputs(buf.c_str(), fp); /* get fd of the FIL...

Can an array be called as a const pointer?

Hello everyone,this is very basic...but please help me if anybody know about this... Can an array be called as a const pointer? ...

functions returning char pointer

I came across lot of functions returning char pointers in one legacy application. Some of them returning pointers to local character arrays. It seems to be causing crashes after several invocations(not immediately!) see the usage below char *f1(){ char buff[20]; char *ptr; ---- ---- ptr=buff; return ptr; } --- --- f2(f1())...

Calling a c-method with a c-style array as a parameter from C# .NET

I have a method defined in an unmanaged DLL: int foo(somestruct * vector, int size) How can I call this method from C#? I've tried with MarshalAs Unmanaged.LPArray with no success. Am I required to use IntPtr and manually serialize into a List or similar. I can't for the life of me find documentation on this on MSDN. Essentially, I ...