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.

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

2 Responses to Find Where Types are Passed by Value

  1. Aviv Hurvitz's avatar 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 to Aviv Hurvitz Cancel reply