- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I've run into this a number of times before, and wondered if there is some preferred way to handle things. If you create a subroutine and specify the intent of each argument, then unless there is an explicit assignment to that variable one will receive a warning "A dummy argument with an explicit INTENT(OUT) declaration is not given an explicit value." Which is true.
However this occurs when an argument is then directly passed to a Win32 routine, which in turn writes the variable. However because that routine is itself not declared with INTENT attributes on the formal parameters, the compiler has no way of knowing that and thus the warning message.
Possible ways of handling this are:
1. Provided Win32 interfaces should include INTENT attributes on formal parameters.
2. Suppress warnings with compiler switch.
3. Always use a local variable in such cases with the Win32 call and copy the result back to the actual parameter.
4. Don't use INTENT in routines that result in this warning.
The right way seems to be number 1, however either this would need to be provided or the user would need to redefine the interface for each Win32 routine used in this manner. So what is the proper approach?
James
However this occurs when an argument is then directly passed to a Win32 routine, which in turn writes the variable. However because that routine is itself not declared with INTENT attributes on the formal parameters, the compiler has no way of knowing that and thus the warning message.
Possible ways of handling this are:
1. Provided Win32 interfaces should include INTENT attributes on formal parameters.
2. Suppress warnings with compiler switch.
3. Always use a local variable in such cases with the Win32 call and copy the result back to the actual parameter.
4. Don't use INTENT in routines that result in this warning.
The right way seems to be number 1, however either this would need to be provided or the user would need to redefine the interface for each Win32 routine used in this manner. So what is the proper approach?
James
Link Copied
4 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I don't see what could be added to so comprehensive and precise post :-). You detected and isolated the problem and offered solutions -- what can we add?. Personally, I'd use INTENT(INOUT)s or remove INTENTs -- not quite adequate but closest to the purpose. Of course, 1) is the Real Thing but I don't think we can justify vendor's effort for providing INTENTs in interfaces -- I'm happy enough with the fact that APIs are finally complete.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
We'd love to provide INTENT on the Win32 API declarations, but that information isn't in the C header files, which we translate, so it would mean reading the documentation for each routine, hoping it is accurate, and hand-editing the declarations, and then redoing this when MS comes up with new declarations. Not a task we're willing to take on, to be honest.
I suppose the compiler could suppress the warning when the argument is passed to something that has no INTENT specified, but I think that weakens the usefulness of INTENT.
Steve
I suppose the compiler could suppress the warning when the argument is passed to something that has no INTENT specified, but I think that weakens the usefulness of INTENT.
Steve
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Jugoslav - I can certainly sympathize with the problem of using source header files that lack this information (same with PURE, etc). Perhaps the Platform SDK documentation is in some consistent format where the information could be pulled out of there during the conversion process? Anyhow my solution is probably going to be to remove the INTENTs, that is too bad because I'm trying to teach some "C" programmers how to do it right. :-)
Steve - I do think that defaulting INTENT(UNSPECIFIED) (so to speak) with INTENT(INOUT) makes sense. Or having a way of specifying the default INTENT. This seems reaonably consistent with the intent of INTENT, and would allow clean compiles on this sort of code.
James
Steve - I do think that defaulting INTENT(UNSPECIFIED) (so to speak) with INTENT(INOUT) makes sense. Or having a way of specifying the default INTENT. This seems reaonably consistent with the intent of INTENT, and would allow clean compiles on this sort of code.
James
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Steve: We'd love to provide INTENT on the Win32 API declarations, but that information isn't in the C header files, which we translate
James: ...that is too bad because I'm trying to teach some "C" programmers how to do it right. :-)
At least now you have a helluva excuse :-). (And having a good excuse is the most important thing in life :-) )
James: ...that is too bad because I'm trying to teach some "C" programmers how to do it right. :-)
At least now you have a helluva excuse :-). (And having a good excuse is the most important thing in life :-) )

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page