views:

212

answers:

3

At the following URL: https://developer.mozilla.org/en/XPCOM_Interface_Reference/nsICacheVisitor is the following code chunk:

boolean visitDevice(in string deviceID, in nsICacheDeviceInfo deviceInfo);

I thought I was dealing with c++, but "in" is not a c++ keyword according to c++ keyword lists i looked up, nor is it a java keyword. So what's it there for and what's it mean?

+3  A: 

It means that the parameter is an input parameter, meaning that it will be used but not modified by the function.

The opposite of an in parameter is an out parameter, which means that the parameter is going to be modified, but not explicitly returned. If you were to use an out parameter after a method that uses it, the value is going to (potentially) be different.

As nos points out in the comment, the page you linked to is describing a .idl, or Interface definition language, file. I'm not familiar with the IDL that Mozilla uses (but if you want to learn more, you can read about it here), but I am somewhat familiar with the Object Management Group's IDL, which says that in parameters are call-by-value, out parameters are call-by-result, and inout parameters are call-by-value/result.

Thomas Owens
I thought it might mean that, but the syntax confused me. is "in" a keyword of some language or have they written the documentation using some sort of pseudocode standard?
Nathan Ridley
As you'll see on that page, it is the documentation for an .idl file, not a C/C++ file. See https://developer.mozilla.org/en/XPIDL
nos
pl/sql uses the keywords in and out in code.
antony.trupe
Thanks for pointing that out. The OMG IDL is where I've seen in and out (along with inout) before.
Thomas Owens
+3  A: 

The language is Mozilla's Interface Description Language (XPIDL). The keyword "in" is described here: here

Eddie Sullivan
A: 

I've seen frameworks/SDKs for C/C++ that define macros to indicate whether a parameter is for input, output or both. I'm guessing that that's what's going on in your example.

For example, the Windows DDK does this for IN OUT and INOUT (if I remember right). When compiling these macros are defined to nothing, they have the potential to be defined to something useful for other tools (like an IDL compiler or a static analysis tool). I;m not sure if they still use these macros in the more recent DDKs.

Microsoft has taken this idea to an extreme with the SAL macros that give a very fine level of control over what behavior is expected for a parameter.

Michael Burr