Find Where Types are Passed by Value

Say you’re working on a large code base, and you came across several instances where some type of non-negligible size was passed as argument by value – where it was more efficient to pass by const reference. Fixing a few occurrences is easy, but how can you efficiently list all places throughout the code where this happens?

Here’s a trick: define the type as aligned, and rebuild. The compiler would now shout exactly where the type is passed by value, since aligned types cannot be passed as such.

Double clicking every such error would get you immediately to where a fix is probably in order.

Advertisements
This entry was posted in VC++. Bookmark the permalink.

2 Responses to Find Where Types are Passed by Value

  1. Aviv Hurvitz says:

    That’s a nice trick! Useful if you have colleagues that were trained in c# or Java. Those guys will forever pass stuff by value without giving it any thought.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s