c

Help with Operator in C

Does ** have any special meaning in C? Like this: static intparse_one (int argc, char **argv) { cmd_line *slot; int value; Flag_name flag_name; int i; printf("argv %s\n",argv); printf("argv[0] %c\n",**argv); If so, does the line **argv make sense? A program I am trying to get to ru...

Switch/case without break inside DllMain

I have a Dllmain that allocates Thread local storage when a thread attaches to this DLL. Code as below: BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) { LPVOID lpvData; BOOL fIgnore; switch (ul_reason_for_call) { case DLL_PROCESS_A...

How do I bit shift a long by more than 32 bits?

It seems like I should be able to perform bit shift in C/C++ by more than 32 bits provided the left operand of the shift is a long. But this doesn't seem to work, at least with the g++ compiler. Example: unsigned long A = (1L << 37) gives A = 0 which isn't what I want. Am I missing something or is this just not possible? -J ...

How to reliably get size of C-style array?

How do I reliably get the size of a C-style array? The method often recommended seems to be to use sizeof, but it doesn't work in the foo function, where x is passed in: #include <iostream> void foo(int x[]) { std::cerr << (sizeof(x) / sizeof(int)); // 2 } int main(){ int x[] = {1,2,3,4,5}; std::cerr << (sizeof(x) / sizeof...

fgets and strcmp [C]

I'm trying to compare two strings. One stored in a file, the other retrieved from the user (stdin). Here is a sample program: int main() { char targetName[50]; fgets(targetName,50,stdin); char aName[] = "bob"; printf("%d",strcmp(aName,targetName)); return 0; } In this program, strcmp returns a value of -1 when ...

Generating moderately interesting images

Abstract: Can you propose a mathematical-ish algorithm over a plane of pixels that will generate a moderately interesting image, preferably one that on the whole resembles something? The story thus far: Once upon a time I decided in an effort to reduce cycle waste on my (admittedly too) numerous computers, and set out to generate image...

Getting back into C/C++ after several years

While at university I started my first programming with ANSI C, before we moved onto Java later in the course. Now I would like to go back to (re)learning C and C++ again to allow me to contribute with open source projects and also to expand my CV and improve my career prospects. Currently I mostly program in VB.net (I know I know, I t...

Is the next C standard actively developed?

Is there currently a group working on the next C standard (by next, I mean after C99)? If so, what are the features likely to make it in? ...

Why is my computer not showing a speedup when I use parallel code?

So I realize this question sounds stupid (and yes I am using a dual core), but I have tried two different libraries (Grand Central Dispatch and OpenMP), and when using clock() to time the code with and without the lines that make it parallel, the speed is the same. (for the record they were both using their own form of parallel for). T...

Checking range with command line arguments

Working on a simple C program I'm stuck with an if test: int line_number = 0; if ((line_number >= argv[2]) && (line_number <= argv[4])) gcc says: cp.c:25: warning: comparison between pointer and integer cp.c:25: warning: comparison between pointer and integer What can I do to properly check the range of lines I want to deal with?...

Sort Hash Tables Glib - qsort

I'm trying to sort a GLib hash table by id that looks something like: key - id { "Red", 2, "BLue", 4, "Yellow", 5, "Orange", 8 } I'm just not sure how to approach this because GLib does not have a sort method. I was thinking to use qsort or GCompareFunc Any ideas will be appreciate it! ...

Using ACE_Service_Object

I'm trying to use the ACE_Service_Object or the ACE_Shared_Object. I'm not sure which one is applicable. I'm trying to encapsulate some functionality in a DLL so a consumer of the DLL would open the library, create an instance of the exported class, call some functions on the class, and then destroy the class. A basic plug-in architec...

Store address dynamic array in c

I'm trying to save the address of a dynamic array index. The last line of this function is what gives the pointer error. static struct sstor *dlist struct node *ins_llist(char *data, struct llist *l) { struct node *p, *q; q = malloc((size_t)sizeof(struct node)); if(q == NULL) return(NULL); if(ins_list(data, &dli...

Monitoring Processes of Window OS using c language

I want to make an application in c or c++ which have to monitor some specific processes. Kindly guide me how I can make it possible in c. ...

Does anyone here use the make-cdf & stats.pl program?

I came across this page: Plotting Tools where I found a set of tools with the name stats.pl and make-cdf. I can write my own but don't want to spend too much time when someone else has already done that. Does anyone have these tools or at least point me to a similar set of tools somewhere? ...

GNU readline: avoid prompt string in output if input is not interactive

I have a readline-based application with a prompt, however I'd like it to not show when the input is not interactive. $ ./readline-app < command-list > result $ cat result prompt> Output line 1 prompt> Output line 2 prompt> $ How can I make the prompt to not print in this case? ...

Difference between cast used in Compound literals and that done on a pointer variable?

Consider the following code: int main() { int *p; ++((int){5}); //compile without err/warning &((int){5}); //compile without err/warning ++((char *)p); //Compile-time err: invalid lvalue in increment &((char *)p); //Compile-time err: invalid lvalue in unary '&' } Why do the Compound Literals do not ...

C warning implicit declaration of function 'exit'

This is my warning. implicit declaration of function 'exit' How i can remove it. i am using linux & gcc compiler. ...

OpenGl Deployment: Running it on other peoples computers!

I'm kind of confused here. Im using a mac trying to develop an opengl game. The Opengl frame work is dynamically linked. So therefore i need to force static or bundle it right? Wait, wait, i read that opengl is on all macs now, yet there's extra stuff u get if u install Xcode.(i have it installed). Anyways, I want this to work on OSX, w...

Disable keyboard keys when the console of c Run using c or c++

I want to disable keyboard when my program Run, means that no one can use alt+F4 etc. How I can make it possible using c in window OS. ...