I was taking a look at the assert() reference page and I got stuck while I read the given example:
/* assert example */
#include <stdio.h>
#include <assert.h>
int main ()
{
FILE * datafile;
datafile=fopen ("file.dat","r");
assert (datafile);
fclose (datafile);
return 0;
}
In this example, assert is used to abort the pr...
I am reading and writting a structure into a text file which is not readable. I have to write readable data into the file from the structure object.
Here is little more detail of my code:
I am having the code which reads and writes a list of itemname and code into a file (file.txt). The code uses linked list concept to read and write d...
pthread_rwlock t1;
pthread_rwlock_wrlock(&t1);
pthread_rwlock t2 = t1;
what happend?
is t2 locked or not?
...
Hi
To make a struct's members "private" to the outside I know that I can do this.
In the .h file
typedef struct Obj Obj;
In the .c file you then
struct Obj {
int a;
int b;
}
This will keep the knowledge of the existense of a and b from beeing known. But all the "member" functions in the .c file will now about them and can oppera...
Hello everybody!
My program (a text-mode web browser) is dynamically allocating memory.
I do free unneeded blocks during runtime, of course. And I do free everything before normal termination - so that memory leak checkers won't give me false positives (and to be flexible should major refactorings ever become needed).
Now, what I do n...
So I found this grate C FFMpeg official example which I simplefied:
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#ifdef HAVE_AV_CONFIG_H
#undef HAVE_AV_CONFIG_H
#endif
#include "libavcodec/avcodec.h"
#include "libavutil/mathematics.h"
#define INBUF_SIZE 4096
#define AUDIO_INBUF_SIZE 20480
#define AUDIO_REFILL_THRESH 409...
I was going through this link Will it optimize and wondered how can we know what optimizations are done by a particular compiler.
Like does VC8.0 convert if-else statements to switch-case?
Is such information available on msdn?
...
What is the cost of malloc(), in terms of CPU cycles?
(Vista/OS, latest version of gcc, highest optimization level,...)
Basically, I'm implementing a complex DAG structure (similar to a linked list)
composed of some 16B (less common) and 20B nodes (more common).
Occasionally, I will have to remove some nodes and then add some.
But, ra...
I want to write a generic (C/C++) library that I will use to develop daemons in the Linux environment. Rather than reinventing the wheel, I thought I'd come in here to find out if there are any well known libraries in use.
The library could be either C or C++ - although I would prefer C++ (maybe something that was part of, or based on t...
Hello,
My app is running out of memory. To resolve this, I free up two very large arrays used in a function that writes a framebuffer to an image. The method looks like this:
-(UIImage *) glToUIImage {
NSInteger myDataLength = 768 * 1024 * 4;
// allocate array and read pixels into it.
GLubyte *buffer = (GLubyte *) malloc(my...
GetVolumePathName() API failed and GetLastError() returned ERROR 158: ERROR_NOT_LOCKED.
What is the reason for this error and how to overcome it?
...
The following code in python takes very long to run. (I couldn't wait until the program ended, though my friend told me for him it took 20 minutes.)
But the equivalent code in Java runs in approximately 8 seconds and in C it takes 45 seconds.
I expected Python to be slow but not this much, and in case of C which I expected to be faste...
Hi,
How to write a macro which calls goto END_ label?
For ex:
#define MY_MACRO() \
//How to define goto END_##function_name label??
my_function()
{
MY_MACRO();
END_my_function:
return;
}
The MY_MACRO should simply replace with the line
goto END_my_function;
...
does anybody knows how to retrieve the http status in gSoap?
I have "HTTP/1.1 202 ACCEPTED..." and I want to print the 202 somehow.
...
In section 7.1.1 of the book "The C++ Programming Language" the author states:
"inline function still has a unique address and so do the static variables of an inline function"
I am confused. If I have an inline function then it can't have address. Does this happen in C also?
...
I was wondering if someone could explain to me what the #pragma pack preprocessor statement does and more importantly why one would want to use it. I checked out the msdn on this http://msdn.microsoft.com/en-us/library/2e70t5y1(VS.80).aspx, which offered some insight, but I was hoping to hear more from people with experience. I've seen i...
What is C# analog of C fread()?
In C code here we use
fread(inbuf, 1, AUDIO_INBUF_SIZE, f);
What could be its exact analog?
...
I can't find a tutorial showing me how this works and I don't get it. I'd like to use it to draw dashed lines since I have an algorithm that generates triangles and would like it to skip some after a certain distance has been reach (a bit like glLineStipple)
Thanks
...
I have a function which reallocs a pointer given as an argument to a new size. Now, the problem is that - according to the man page - realloc needs a pointer which has been returned by malloc or calloc before.
How can I make sure that the caller passes a pointer that meets those requirements?
There seem to be no build-in C mechanics (li...
I'm fairly sure the answer to this is 'no, don't be stupid', but as they say, there are no stupid questions (only stupid people asking them).
I want to calculate the offset of an array. I have a void * handle to it and the sizeof(element). I don't have an x* pointer (where x is the type of the element).
Is there any way I can cast the...