P
Peter
I'm working through Sheng Liang's "The JNI Programmer's Guide and
Specification", and am on chapter 3, working the "Prompt" example. I'm
working through all the examples using gcc on GNU/Linux and VC++ on MS
Windows. Here's the C code in Sheng's book:
#include <stdio.h>
#include "Prompt.h"
JNIEXPORT jstring JNICALL
Java_Prompt_getLine( JNIEnv *env, jobject obj, jstring prompt )
{
char buf[128];
const jbyte *str;
str = (*env)->GetStringUTFChars( env, prompt, NULL );
if ( str == NULL ) return NULL;
printf("%s", str);
(*env)->ReleaseStringUTFChars(env, prompt, str);
scanf("%s", buf);
return (*env)->NewStringUTF(env, buf);
}
When I compile this with gcc, I get the warnings:
Prompt.c: In function Java_Prompt_getLine() Prompt.c:16: warning: pointer
targets in assignment differ in signedness
Prompt.c:20: warning: pointer targets in passing argument 3 of
(*env)->ReleaseStringUTFChars() differ in signedness
The code to focus on here is:
const jbyte *str;
str = (*env)->GetStringUTFChars( env, prompt, NULL );
(*env)->ReleaseStringUTFChars(env, prompt, str);
Looking into jni.h:
const char* (JNICALL *GetStringUTFChars)
(JNIEnv *env, jstring str, jboolean *isCopy);
void (JNICALL *ReleaseStringUTFChars)
(JNIEnv *env, jstring str, const char* chars);
And from linux/jni_md.h:
typedef signed char jbyte;
Doing some Googling, it appears that the C standard allows char to be either
signed or unsigned by default. Using a small test program where I set a char
variable equal to 255, it appears that with gcc on GNU/Linux, a char by
default is signed.
So I don't see the problem here.
* GetStringUTRChars() returns a ptr to a signed char.
* The 3rd arg of ReleaseStringUTFChars() takes a ptr to a signed char.
* A jbyte is a signed char
So what exactly is gcc complaining about?
Thanks for reading down this far.
Pete
Specification", and am on chapter 3, working the "Prompt" example. I'm
working through all the examples using gcc on GNU/Linux and VC++ on MS
Windows. Here's the C code in Sheng's book:
#include <stdio.h>
#include "Prompt.h"
JNIEXPORT jstring JNICALL
Java_Prompt_getLine( JNIEnv *env, jobject obj, jstring prompt )
{
char buf[128];
const jbyte *str;
str = (*env)->GetStringUTFChars( env, prompt, NULL );
if ( str == NULL ) return NULL;
printf("%s", str);
(*env)->ReleaseStringUTFChars(env, prompt, str);
scanf("%s", buf);
return (*env)->NewStringUTF(env, buf);
}
When I compile this with gcc, I get the warnings:
Prompt.c: In function Java_Prompt_getLine() Prompt.c:16: warning: pointer
targets in assignment differ in signedness
Prompt.c:20: warning: pointer targets in passing argument 3 of
(*env)->ReleaseStringUTFChars() differ in signedness
The code to focus on here is:
const jbyte *str;
str = (*env)->GetStringUTFChars( env, prompt, NULL );
(*env)->ReleaseStringUTFChars(env, prompt, str);
Looking into jni.h:
const char* (JNICALL *GetStringUTFChars)
(JNIEnv *env, jstring str, jboolean *isCopy);
void (JNICALL *ReleaseStringUTFChars)
(JNIEnv *env, jstring str, const char* chars);
And from linux/jni_md.h:
typedef signed char jbyte;
Doing some Googling, it appears that the C standard allows char to be either
signed or unsigned by default. Using a small test program where I set a char
variable equal to 255, it appears that with gcc on GNU/Linux, a char by
default is signed.
So I don't see the problem here.
* GetStringUTRChars() returns a ptr to a signed char.
* The 3rd arg of ReleaseStringUTFChars() takes a ptr to a signed char.
* A jbyte is a signed char
So what exactly is gcc complaining about?
Thanks for reading down this far.
Pete