Re: [Fresco-devel] Suggested addition to Coding Style-guide
Gabriel Dos Reis <[email protected]> 12 Apr 2003 20:16:34 +0200
| Newsgroups | gmane.comp.video.fresco.devel |
|---|---|
| Organization | Integrable Solutions |
| Message-ID | <[email protected]> |
Neil Pilgrim <[email protected]> writes: | ---- | When using a class name in a function declaration such as: | | void do_foo(some_type &x); | int do_bar(type_space::nested_type *y); | | it is often not necessary to include the entire header file in which the | types are declared. Instead it is preferable, to reduce build-time | dependencies, to use: | | void do_foo(class some_type &x); | | or if some_type is used multiple times within the same file (or the | class is within a namespace), to predeclare: | | class some_type; | namespace type_space | { | class some_type; | }; | /* ... */ | void do_foo(some_type &x); | void do_bar(type_space::nested_type *y) | ---- | | In quite a few instances (if not a *lot*!) we don't currently do this; | it seems like a good common idea, so assuming no discussion to the | contrary it'd be good to add it to the coding guide. Oh, and implement | it ;) | | Comments? I would suggest you don't repeat declarations all over the places as suggested above. While that might be seem a reasonable practice in C, it is recommanded for C++ coding that you : (a) include the appropriate header files (b) design a forward-declaration header and do (a) The point is that C++ tends to be very picky about declarations and name-lookup are already complicate; it is better to include a heade file that provides the "true" declarations in every translation unit. You'll also find that what you're proposing does not scale to standard types and functions. It is therefore preferable to have a coding style that apply both to standard headers and Fresco entities. -- Gaby