I am working on a certain application built on Java. The java layer talks to C++ layer which does the logic of forming sql queries from database and returns the result back to the Java layer.
With a simpler example :
On the java side
nameField = new JTextField(20) //20 chars max length
name = t.getText() // name is sent to CPP layer
On the CPP layer, name from java layer is received and stored in a local variable say cppName. I am confused about the declaration of variables used in CPP layer. Most of them are declared like this :
char cppName[20*4+1]
I want to know the significance of 20*4+1 here. The reason for declaring all variables on cpp side with size as javaSize*4+1.
Are the characters in the java code UNICODE? If so, a single
charisn’t enough to store a UNICODE character, the ratio is4:1. The final character (+1) is the null terminator.So you need 4 bytes, which is 4
chars, in the C++ side to store a single Java character, and char-represented strings in C++ are null-terminated (last character has to be'\0'), so20*4+1.