In various multi threaded C and C++ projects I've seen the -pthread flag applied to both the compiling and linking stage while others don't use it at all and just pass -lpthread to the linking stage.
Is there any danger not compiling and linking with the -pthread flag - i.e. what does -pthread actully do ? I'm primarly interrested in li...
I'm trying to create a program which takes in a set number of strings (the user is asked to put in the number of strings they will enter), once it has these strings, they are placed in an array, using dynamic memory.
The ouput would be something like this:
# of Strings: 3
Cat
Dog
Elephant
Cat
Dog
Elephant
Heres a snippet of my code...
I'm working on a problem where I'm given a sorted array of integers, and I am supposed to take an input from the user, search for the input, and return the first instance of that input (if it exists) and the number of times it appears.
I wrote a program with the following approach: I take an input from the user. I then use binary search...
If i use UDP sockets for interprocess communication, can i expect that all send data is received by the other process in the same order?
I know this is not true for UDP in general.
...
hey,
i want to allocate a matrix.
is this the only option:
int** mat = (int**)malloc(rows * sizeof(int*))
for (int index=0;index<row;++index)
{
mat[index] = (int*)malloc(col * sizeof(int));
}
thanks
...
Hello,
I'm using this simple C code:
char * command = NULL;
sprintf (command, "ls %s", folderpath);
system(command);
The problem is when the folder name has a space in it...
I know that in Unix I need to add a "\", for example ls my\ folder\ name
How can I get around this ? Thank you!
...
Hi,
I have installed opencv c libraries from package management into my Kubuntu 9.10. I wrote a small image modification program that uses those libraries, but I can't compile it, because every time I try to compile I get the error message that the functions from opencv library cannot be found.
Those header files are in folder /usr/inc...
I have a question regarding memory allocation order.
In the following code I allocate in a loop 4 strings.
But when I print the addresses they don't seem to be allocated one after the other... Am I doing something wrong or is it some sort of defense mechanism implemented by the OS to prevent possible buffer overflows? (I use Windows Vist...
What's the difference between float* varname and float *varname in classic C?
...
I am using a GNU-make Makefile to build a C project with several targets (all, clean, and a few project specific targets). In the process of debugging, I would like to append some flags to a single build without permanently editing the Makefile (e.g. add debugging symbols or set a preprocessor flag).
In the past, I have done that as fol...
I have a program that has an array of pointers such as:
INTLIST* myArray[countOfRows];
each myArray pointer points to a linked list, basically it becomes an M*N matrix.
So for example:
3 2 1
2 1 0
1 9 8
So myArray[0] is a linked list with 3->2->1 and myArray[1] is a linked list with 2->1->0.. and so on. I have a function that pri...
Hi, I've seen answers here for specific languages, about switches with more than 5 cases being optimized with jump tables to guarantee constant access time for any case.
Is that so for C / C++?
Is it in particular for gcc? for visual studio?
If not, would sorting cases in order of occurrence frequency help?
...
My professor defined this in the .h file
void list_map(INTLIST* list, void (*f)(void *)); /*Applies a function to each element of the list */
I wrote the function like this:
void list_map(INTLIST* list, void (*f)(void *))
{
INTLIST* pTemp=NULL;
if (list == NULL)
{
//list is empty
}
else
{
for(p...
char x[16];
int y = 42 + 256;
char* p = &y;
int* q = p;
char** r = &p;
printf("%d %d %d\n", p, q, r);
why is the value of r always 12 units smaller than p and q? Thank you!
...
What is the best optimal way of finding whether any element is repeated in a given array?
...
Hi,
this is my c code that reads a list of URLs from a file , and tries to separate the various parts of the URL.. This is just rough parsing , i'm not bothered about special cases.. I guess there is some fault with the sscanf() statement , when i run this , i get " segmentation FAULT" .. and moreover , the full url is being assigned t...
You are given an integer 51234 (say) we need to sort the digits of a number the output will be 12345.
How to do it without using array ?
...
I am working in Ansi C, windows platform. I want to attach mysql database to my c program. Kindly guide me how I can make it possible.
...
Hi, all
Is it possible to force gcc use int instruction for all the system calls, but not sysenter? This question may sound strange but I have to compile some projects like Python and Firefox this way.
Summary
Thanks to jbcreix, I've downloaded glibc 2.9 source code, and modified the lines in sysdeps/unix/sysv/linux/i386/sysdep.h, to ...
Hello,
gcc 4.4.2 c89
I re-engineering some code in c89. However, I am totally confused with the code that uses the following #defines. So I created a small application that maybe I would understand more of how this is working.
From what I can gather the MODULE_API will pass a function name and call the macro MODULE_SOURCE_API and con...