C++/C Programming etiquette on passing structures by reference -


i have been writing program has rather large structure passed reference few functions. however, there few other functions need access small pieces of information within large structure. it's not being edited, read.

my question starts here. thinking of creating a second structure copies specific pieces of information needed , passing reference, rather passing entire structure reference.

what wondering 2 things:

1) since passing large structure reference, there no performance impact. correct? 2) if 1) correct, bad etiquette passing around structure shouldn't edited (even though wouldn't edited, still i'm talking principle here).

more specifically:

i have configuration structure sets programs configuration calling function , passing structure reference. there information (process name, command line arguments) want use informative purposes only. i'm asking if it's bad practice pass around structure wasn't meant purpose of want use for.

1) since passing large structure reference, there no performance impact. correct?

correct.

2) if 1) correct, bad etiquette passing around structure shouldn't edited (even though wouldn't edited, still i'm talking principle here).

you let function accept reference const make sure function won't alter state of corresponding argument.

i'm asking if it's bad practice pass around structure wasn't meant purpose of want use for.

i'm not sure mean this. way write it, seems bad practice: shouldn't use doing wasn't meant for. means distorting semantics of object. however, rest of question doesn't seem imply this.

rather, seems concerned passing reference function because may allow function alter argument's state; provided function takes reference const, won't able alter state of argument. in case, no it's not bad practice.

if referring fact function need work some of data members or member functions of structure, again not bad design. silly require each function access every member of data structure.

of course, best can write without knowing concrete semantics of function , particular data structure.


Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -