stringrpc.x

what is string strName<>?


I have seen code like this:

struct failed_login_res {
     string errorMsg<>;
     unsigned int error;
};

What does the <> at the end mean? How is it different from normal declaration like string errorMsg?

Correction: this is for RPC stub, not C++ and I can confirm that it does compile. The question is then still valid.


Solution

  • From a quick googling, I came across this PDF.

    Section 6.9 is as follows:

    Strings: C has no built-in string type, but instead uses the null-terminated “char *” convention. In XDR language, strings are declared using the “string” keyword, and compiled into “char *”s in the output header file. The maximum size contained in the angle brackets specifies the maximum number of characters allowed in the strings (not counting the NULL character). The maximum size may be left off, indicating a string of arbitrary length.

    Examples:

    string name<32>; --> char *name;
    string longname<>; --> char *longname;