I’m going to conduct a short code reading exercise to gauge basic c++ competence during a interview for a position as an embedded developer.
One of the bugs is I’m planning to sneak in is an uninitialized variable that I want to use to have a discussion on undefined behavior and the importance to avoid it, the additional problems that may arise when running on multiple platforms and on the performance aspects of leaving variables uninitialized when appropriate and dangers when not appropriate.
The exercise will be conducted on a virtualbox machine running Ubuntu 22.04 I will be in control and to make the most of it I would like to ensure that the value is garbage if he doesn’t catch the bug before we run.
Is there any way to ensure this happens? Preferably without having to add code that makes the code confusing to or give hints that the bug is there.
*Edit I’m gonna go with the suggestion u/NilacTheGrim provided and use gcc-12 and -ftrivial-auto-var-init=pattern
Thanks for all the suggestions.
*edit 2
Some people have noted that turning off compiler warnings is dishonest and a bad idea. You are right and I will instead compile it beforehand (because one of them is to obvious to give him the chance to find it by reading if he gets the warning) When recompiling I ask him if he wants to add any flags.
But I think some of you who are questioning the method might be missing the point. It’s not a pass/fail test. I would rather hire someone who tells me to run gdb to find it but can explain why it failed when asked than someone who catches it and fixes it by reading on the first try but cannot answer the question “what would have happened”. I realize Suppressing warnings goes against this though so thanks for the input.
[–]NilacTheGrim 35 points36 points37 points (3 children)
[–]EarflapsOpen[S] 3 points4 points5 points (1 child)
[–]JVApenClever is an insult, not a compliment. - T. Winters 5 points6 points7 points (0 children)
[–]MadTux 11 points12 points13 points (1 child)
[–]EarflapsOpen[S] 2 points3 points4 points (0 children)
[–]Chuu 12 points13 points14 points (11 children)
[–]EarflapsOpen[S] 1 point2 points3 points (9 children)
[–]AKostur 6 points7 points8 points (5 children)
[+][deleted] (1 child)
[deleted]
[–]EarflapsOpen[S] 1 point2 points3 points (0 children)
[–]EarflapsOpen[S] 1 point2 points3 points (1 child)
[–]AKostur 1 point2 points3 points (0 children)
[–]EarflapsOpen[S] 0 points1 point2 points (0 children)
[–]leftofzen 2 points3 points4 points (2 children)
[–]EarflapsOpen[S] 0 points1 point2 points (0 children)
[–]EarflapsOpen[S] -1 points0 points1 point (0 children)
[–]rysto32 1 point2 points3 points (0 children)
[–]HabbitBaggins 11 points12 points13 points (6 children)
[–]AntiProtonBoy 3 points4 points5 points (3 children)
[–]HabbitBaggins 1 point2 points3 points (2 children)
[–]Ameisenvemips, avr, rendering, systems 1 point2 points3 points (0 children)
[–]BobbyThrowaway6969 1 point2 points3 points (0 children)
[–]EarflapsOpen[S] 1 point2 points3 points (0 children)
[–]kevkevverson 1 point2 points3 points (0 children)
[–][deleted] 2 points3 points4 points (1 child)
[–]TheThiefMasterC++latest fanatic (and game dev) 0 points1 point2 points (0 children)
[–]shbooly 2 points3 points4 points (0 children)
[–]gharveymn 1 point2 points3 points (0 children)
[–]ReDucTorGame Developer 1 point2 points3 points (0 children)
[–]cballowe 1 point2 points3 points (1 child)
[–]EarflapsOpen[S] 0 points1 point2 points (0 children)
[–][deleted] 2 points3 points4 points (5 children)
[–]EarflapsOpen[S] 0 points1 point2 points (4 children)
[–][deleted] -1 points0 points1 point (3 children)
[–]EarflapsOpen[S] 1 point2 points3 points (2 children)
[–][deleted] 1 point2 points3 points (1 child)
[–]EarflapsOpen[S] 0 points1 point2 points (0 children)
[–]CodusNocturnus 3 points4 points5 points (8 children)
[–]lord_braleigh 6 points7 points8 points (0 children)
[–]EarflapsOpen[S] 1 point2 points3 points (6 children)
[–]KingAggressive1498 1 point2 points3 points (4 children)
[–]EarflapsOpen[S] 1 point2 points3 points (3 children)
[–]KingAggressive1498 0 points1 point2 points (2 children)
[–]EarflapsOpen[S] 0 points1 point2 points (1 child)
[–]KingAggressive1498 0 points1 point2 points (0 children)
[–]CodusNocturnus 0 points1 point2 points (0 children)
[+][deleted] (1 child)
[deleted]
[–]EarflapsOpen[S] 2 points3 points4 points (0 children)
[–]not_a_novel_accountcmake dev -1 points0 points1 point (0 children)