Question re: Usage of JNICALL with varargs function with 32bit compilers

Steve Groeger GROEGES at uk.ibm.com
Tue Jun 18 11:30:47 UTC 2019


Hi all, 

I had a query regarding the use of JNICALL with varargs functions, which I 
am hoping someone can comment on.

As explained on MSDN at [1], all functions declared as __stdcall that have 
variable parameters (varargs) will be forced back to __cdecl by the MSVC. 
In such case, keeping JNICALL for varargs functions/function pointers 
turns out be inappropriate.
e.g.

include/jni.h
    jobject (JNICALL *NewObject)
      (JNIEnv *env, jclass clazz, jmethodID methodID, ...);

According to [2], stdcall does not support variadic calls in C on 32-bit 
x86 targets. 

When compiling a JNI native (calling NewObject) with Clang, it ends up 
with the warning as follows:
...\include\jni.h:277:14: warning: stdcall calling convention ignored on 
variadic function [-Wignored-attributes]
    jobject (JNICALL *NewObject)
             ^

So basically the compiler is saying it can't do what was requested, as 
such should we stop asking for JNICALL on varargs functions. 
Doing so will only improve the portability of code to a wider set of 
compilers.

Comments?

[1] https://msdn.microsoft.com/en-us/library/zxk0tw93.aspx
[2] https://clang.llvm.org/docs/AttributeReference.html#stdcall

Thanks
Steve Groeger
IBM Runtime Technologies
Hursley, Winchester
Tel: (44) 1962 816911  Mobex: 279990  Mobile: 07718 517 129
Fax (44) 1962 816800
Lotus Notes: Steve Groeger/UK/IBM
Internet: groeges at uk.ibm.com

Unless stated otherwise above:
IBM United Kingdom Limited - Registered in England and Wales with number 
741598.
Registered office: PO Box 41, North Harbour, Portsmouth, Hampshire PO6 3AU
Unless stated otherwise above:
IBM United Kingdom Limited - Registered in England and Wales with number 
741598. 
Registered office: PO Box 41, North Harbour, Portsmouth, Hampshire PO6 3AU



More information about the core-libs-dev mailing list