0

enter image description here

I have a problem with registering methods using JNI, if i want to use "method_name", compiler throws me error about that.

typedef struct {
    char *name;
    char *signature;
    void *fnPtr;
} JNINativeMethod;

How to type method name without crazy conversions like std::string -> const char* -> char*? Is it possible?

Main problem is that JNIMethod struct require char* not const char* that's why I'm asking

Kaspek
  • 159
  • 1
  • 11
  • In C++ you can't initialize a `char*` with a string literal. You have to have `const char*`. See [Deprecated conversion from string literal to 'char*'](https://stackoverflow.com/questions/9650058/deprecated-conversion-from-string-literal-to-char) or [Why is conversion from string constant to 'char*' valid in C but invalid in C++](https://stackoverflow.com/questions/20944784/why-is-conversion-from-string-constant-to-char-valid-in-c-but-invalid-in-c) – Jason Aug 23 '22 at 14:31
  • @JasonLiam: It _was_ deprecated in C++03, but the code in the picture is C++20. It's currently just plain illegal. – MSalters Aug 23 '22 at 14:33
  • @MSalters Yup, it is invalid/illegal now. I was just mentioning the dupe. I've added some more dupes in the dupe list. – Jason Aug 23 '22 at 14:34
  • @JasonLiam but well how to use it in JNI struct with methods where char* is required not const char* – Kaspek Aug 23 '22 at 14:51
  • 1
    `std::strdup("bake")` ... but then what code is responsible for cleaning up that allocation? Or just leak...? – Eljay Aug 23 '22 at 15:06

0 Answers0