c

Thread-safe get (accessor method)

I'm currently using the following code for thread-safe access of a variable. int gnVariable; void getVariableValue(int *pnValue) { acquireLock(); //Acquires the protection mechanism *pnValue = gnVariable; releaseLock(); //Releasing the protection mechanism } I would like to change my API signature to a more user-friendly ...

what is mean by "memory is 8 bytes aligned"?

hi , while going through one project , i have seen that the memory data is "8 bytes aligned" Can anyone please give some input related to this ? /Kanu__ ...

C programming question on the implementation of a hash table

Hi, I have a C programming question on the implementation of a hash table. I have implemented the hash table for storing some strings. I am having a problem while dealing with hash collisons. I am following a chaining linked-list approach to overcome the problem but, somehow, my code is behaving differently. I am not able to debug it. Ca...

Goal of C's "auto" keyword

What is the goal of the "auto" keyword in C? With C++ 0x it got new meaning but does it mean that my code will break if I port C code over to a C++ 0x compiler? ...

reference other projects in visual studio for win32 projects

Hi All I am working with win32 API and my language of choice is pure C and no C++. Assume I have a project A that is present in Solution S in visual studio I want to add another project B(which has some common utility functions) in to S Now I want to reference Project B in Project A... So that I can use those utility functions from ...

String Manipulation in C

Hi guys, I am helping my nephew for his C lab homework, it is a string manipulation assignment and applying Wang's algorithm. Here is the BNF representation for the input. <s> ::= <l> # <r> <l> ::= <list>| ε <r> ::= <list>| ε <list> ::= <f>|<f> , <list> <f> ::= <letter>| - <f>| (<f><op><f>) <op> ::= & | | | > <letter> ::= A |... | Z ...

Access static constant variable from multiple threads in C

I have some experience with multithread programming under Linux (C/C++ & POSIX threads), however most obvious cases are sometimes very complicated. I have several static constant variables (global and function local) in my code, can I access them simultaneously from multiple threads without using mutexes? Because I don't modify them it ...

How could my code compile correctly without necessary headers?

I use the functions fork(),exec()... But how can this program be compiled without including some extra headers (like sys/types.h, sys/wait.h). I use ubuntu 10.04 with gcc version 4.4.3 #include <stdio.h> #include <stdlib.h> int main() { pid_t pid; printf("before fork\n"); pid = fork(); if(pid == 0) { /*child*/ if(execvp("...

math library in gcc

I am writing a program on linux gcc... When I tried to include <math.h> I found that I need to link math library by using command gcc -lm But I am searching for another way to link the math library 'in code', that does not require the user to compile using any options.. Can gcc -lm be done in c code using #pragma or something? EDIT:...

Should a g_object_new have a matching g_object_unref?

I'm using libnotify to show desktop notifications in my application; notify_notification_new() returns a NotifyNotification*, which should be passed as the first param to further function calls of the notification library. There is no notify_notification_free() which frees the pointer it returns. I looked up the source of notify_notifi...

Deleting a node from linked list in C

My problem is deleting a node from linked list. I have two structs : typedef struct inner_list { int count; char word[100]; inner_list*next; } inner_list; typedef struct outer_list { char word [100]; inner_list * head; int count; outer_list * next; } outer_list; My problem is in deleting a node from outer_list linked list....

Parsing NTFS Partition in C

Hello all, I'm just a beginner and I have a need to parse a NTFS partition for the purpose of extracting Security Descriptors. (I been trying to use the native functions of the Windows API, but my conclusion is that something is seriously wrong with the functions' behavior, or their documentation.) I was wondering if anybody here experi...

Set size of scroll thumb?

I'v looked on MSDN and can't find how to do this. It lets me set the range and position but not the thumb that the user clicks and drags. Thanks ...

Visual Studio 2008 linker wants all symbols to be resolved, not only used ones

We recently upgraded to Visual Studio 2008 from 2005, and I think those error started after that. In our solution, we have a multitude of projects. Many of those are utility projects, or projects containing core functionality used by other projects. The output of those is lib files that are linked to when building the projects generatin...

Downside to including headers in every source file (Objective-C)

I'm currently including my AppDelegate.h and all of my category headers into every one of my source files using the MyApp_Prefix.pch prefix header, instead of manually #importing them only where they are used. The category methods and lots of compiler #define's in my app delegate are used in lots of places in my code. Is there any down...

Can I use a single pointer for my hash table in C?

I want to implement a hash table in the following manner: struct list { char *string; struct list *next; }; struct hash_table { int size; /* the size of the table */ struct list **table; /* the table elements */ }; Instead of struct hash_table like above, can I use: struct hash_table { int size; /* the size ...

Libraries C/C++ for ordered combinations generation and ranking/unranking ?

Hello, I'm looking for a library which could rank/unrank ordered combinations (ranking means from a combination it give you which nth combinations it is from a gray code or lexicographic or some other algorithm, unranking is the reversing process). I look for a library doing many algorithmes like gray code or lexicographic, rev-lexico...

Same code... but warning!Any ideas?

I've a question for a warning message that i get. For this line,using qsort library function: qsort(catalog, MAX ,sizeof catalog, struct_cmp_by_amount); I get this warning: warning: passing argument 4 of ‘qsort’ makes pointer from integer without a cast EDIT: struct_cmp_by_amount is the following function on the program....

is it possible to write a program which prints its own source code utilizing a "sequence-generating-function"

is it possible to write a program which prints its own source code utilizing a "sequence-generating-function"? what i call a sequence-generating-function is simply a function which returns a value out of a specific interval (i.e. printable ascii-charecters (32-126)). the point now is, that this generated sequence should be the programs ...

counting characters program in c

The output of characters number is the actual no. plus 3. I don't know why? This is the code: void main(void) { int ch,w=0,c=0; do { ch=getche(); ++c; if(ch==32) { ++w; ++c; } }while(ch!=13); printf("\nnum of characters is %d",c); printf("\nnum of words is %d",w); getch(); } ...