I want to allocate some memory in C and keep it associated with a java object instance, like this:
void configure(JNIEnv *object, jobject obj, ....) {
char *buf = new char[1024];
// associated <buf> with <obj> somehow
}
And then later free the memory when the java object gets garbage collected - I could do this by calling a JNI fu...
#define PLAINTEXT_TARGET "plaintext"
if( strstr(PLAINTEXT_TARGET, optarg) == PLAINTEXT_TARGET )
/* ... */
Does the C language guarantee that PLAINTEXT_TARGET above compiles into a single instance? If the compiler may produce two instances of the macro string then the conditional above is misleading and can be false.
...
I'm abusing the C preprocessor for my build system to produce a "readme" plain-text file and a web page from the same source file. The construction is something like this:
The actual definitions are in data.h:
#define WEBSITE "http://example.com"
Note that the // in the URL must be quoted, or else it will be treated as the start of a...
I am referring to http://www.postgresql.org/docs/8.1/static/libpq.html
I try to find an example of C/C++ to call PostgreSQL stored procedure. However, I cannot find one. Can anyone point me the right direction?
...
Is there any compiler option to make time_t 64-bit in Solaris 5.8 in forte compiler. I need to develop library in 32-bit and I cannot change it to 64-bit as it effects existing client applications.
...
In Win32 API programming it's typical to use C structs with multiple fields. Usually only a couple of them have meaningful values and all others have to be zeroed out. This can be achieved in either of the two ways:
STRUCT theStruct;
memset( &theStruct, 0, sizeof( STRUCT ) );
or
STRUCT theStruct = {};
The second variant looks clean...
How can I measure the power consumed by a C algorithm while running on a Pentium 4 processor (and any other processor will also do)?
...
int i = 3.1 / 2
does not cause any warnings,even with -Wall option.Sometimes,I would like to know where precision lose.Why gcc does not support this warning,while msvc support this one?
thanks.
EDIT: my gcc -v shows
Configured with: ../../gcc-4.4.1/configure --prefix=/mingw --build=mingw32 --enable-languages=c,ada,c++,fortran,objc,o...
Hi,
I'm practicing C programming for Linux for an exam.
I don't know how to exit the program when user press Ctrl + a ( not Ctrl+c )
For example, looping something until user press Ctrl+a
Could anyone tell me how to check Ctrl+a input?
Notes: I'm using 'gcc' and run output with './a.out'
Thanks in advance for everyone!
...
I have some compiled libraries on x86 Linux and I want to quickly determine whether they were compiled with debugging symbols.
...
Is it possible to get the screen pixel resolution in mm using Win32 APIs ? I have an application which is showing 0.3472222222222222 as the value for this on my 1280x1024 monitor with 96 dpi . But I am not able to find out how it got this value. Any clues will be helpful. I can use MFC also if required.
EDIT
Sorry for the confusion, the...
I have come across a problem while writing a fairly simple program. I have a statically allocated vector as a global variable and in a function I'm trying to change the values of the elements and that is when the program stops and says segmentation fault. The code is something like this:
int a[10] = {0,0,0,0,0,0,0,0,0,0};
...
int bla(...
For OOP languages, there are many books describing how to design software, and design patterns are mainly for OOP languages.
I am wondering whether there are any books/good articles teaching how to use C in a big project, like it is a good practice to use static functions when this function is only used in a single file.
...
I'm developing a dedicated game server on a linux machine, in C/C++ (mixed). I have the following snippet of code:
int sockfd=socket(AI_INET, SOCK_DGRAM, 0);
if(sockfd==-1)
{
int err=errno;
fprintf(stderr,"%s",strerror(err));
exit(1);
}
My problem here, is that socket is returning -1 (implying a failure) and the error stri...
Where can I find some good, proven guidelines or examples on writing extensible, modular, loosely-coupled code in C (if possible)?
Background of our problem is that we are maintaining large plain C, legacy code project for a low-cost microcontroller with limited computing and memory resources. Due to the fact that the system must be ex...
Came across this conditional in some uncommented Objective-C code:
if (w & (w - 1))
{
i = 1;
while (i < w)
{
i *= 2;
}
w = i;
}
Where w is a size_t greater than 1.
Update: Added the code contained by the conditional for context.
...
Hi,
I'm working on a C application that is suppose to talk to PostgreSQL. Right now I need to handle notices and warnings sent by the server but I'm at a loss on how to make it work.
The (very unclear) documentation says we should use PQsetNoticeReceiver to set a method as the receiver of notifications, as the default receiver just for...
I am trying to recompile solution file for memcached project on Windows 7 64 bit with Visual Studio 2008 and got the following error:
1>LINK : fatal error LNK1000: Internal error during IncrBuildImage
1> Version 9.00.21022.08
1> ExceptionCode = C0000005
1> ExceptionFlags = 00000000
1> ExceptionAddress = ...
Hi everyone,
I can't figure out how to display something (like hello world) in every 3 seconds.
I'm writing in only C programming with gcc compiler in linux.
We can stop it by Ctrl+c.
I just want simplest and easiest way to manipulate thet code with my project.
Thank you so much in advance!
...
I have created a macro to make reserve memory for my strings in C. It looks like this:
#define newString(size) (char*)malloc(sizeof(char) + size)
So is there any reason I shouldn't use this macro in my own personal projects? I know I shouldn't do this in production code because it would require everyone to have that header file and ev...