Click here to Skip to main content
15,886,873 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: me vs. VS2022.. detecting NULL pointers Pin
Richard Andrew x641-Mar-24 7:39
professionalRichard Andrew x641-Mar-24 7:39 
GeneralRe: me vs. VS2022.. detecting NULL pointers Pin
trønderen1-Mar-24 13:37
trønderen1-Mar-24 13:37 
GeneralRe: me vs. VS2022.. detecting NULL pointers Pin
jschell1-Mar-24 12:05
jschell1-Mar-24 12:05 
GeneralRe: me vs. VS2022.. detecting NULL pointers Pin
Mircea Neacsu1-Mar-24 15:49
Mircea Neacsu1-Mar-24 15:49 
GeneralRe: me vs. VS2022.. detecting NULL pointers Pin
CPallini1-Mar-24 23:21
mveCPallini1-Mar-24 23:21 
AnswerRe: me vs. VS2022.. detecting NULL pointers Pin
Mircea Neacsu29-Feb-24 12:24
Mircea Neacsu29-Feb-24 12:24 
GeneralRe: me vs. VS2022.. detecting NULL pointers Pin
charlieg29-Feb-24 15:41
charlieg29-Feb-24 15:41 
GeneralRe: me vs. VS2022.. detecting NULL pointers Pin
Mircea Neacsu29-Feb-24 16:39
Mircea Neacsu29-Feb-24 16:39 
charlieg wrote:
I take the phrase "Here be dragons..." seriously.
And so you should. Seems the author of the code in question also took it seriously:
C++
void CInfoBar::SetText(LPCTSTR lpszNew)
{
    ASSERT(lpszNew && AfxIsValidString(lpszNew));
In this case assert seems the proper way to handle a failing precondition: the function cannot work with a NULL pointer. Fullstop!

In the new variant something has changed:
C++
if (NULL != lpszNew)
{
    ASSERT(lpszNew && AfxIsValidString(lpszNew));
The ASSERT after the if is clearly not needed (or it could be simplified to keep just the second condition). Also, more importantly the contract conditions of the function have changed: previously the function said "I cannot deal with NULL values for lpszNew". Now it says "if you pass me a NULL value I'm going to do something about it (possibly an else clause for the if statement or something)".

I'm not saying this is wrong but is something to consider carefully.

PS:
charlieg wrote:
Still I'm amazed that the MS compiler would distinguish between either version of the source.
It's the artificial intelligence Laugh | :laugh:
Mircea

QuestionDATASET Pin
Aryan Gupta 202429-Feb-24 6:51
Aryan Gupta 202429-Feb-24 6:51 
AnswerRe: DATASET Pin
Dave Kreskowiak29-Feb-24 9:34
mveDave Kreskowiak29-Feb-24 9:34 
AnswerRe: DATASET Pin
Richard Deeming29-Feb-24 21:34
mveRichard Deeming29-Feb-24 21:34 
GeneralRe: DATASET Pin
CPallini1-Mar-24 1:52
mveCPallini1-Mar-24 1:52 
QuestionHow to recover missing file ? Pin
Salvatore Terress28-Feb-24 6:08
Salvatore Terress28-Feb-24 6:08 
AnswerRe: How to recover missing file ? Pin
Maximilien28-Feb-24 7:37
Maximilien28-Feb-24 7:37 
GeneralRe: How to recover missing file ? Pin
Salvatore Terress28-Feb-24 10:51
Salvatore Terress28-Feb-24 10:51 
QuestionRe: How to recover missing file ? Pin
Richard MacCutchan28-Feb-24 8:00
mveRichard MacCutchan28-Feb-24 8:00 
AnswerRe: How to recover missing file ? Pin
jschell28-Feb-24 12:26
jschell28-Feb-24 12:26 
AnswerRe: How to recover missing file ? Pin
k505428-Feb-24 12:34
mvek505428-Feb-24 12:34 
GeneralRe: How to recover missing file ? Pin
Salvatore Terress29-Feb-24 1:11
Salvatore Terress29-Feb-24 1:11 
GeneralRe: How to recover missing file ? Pin
k505429-Feb-24 5:19
mvek505429-Feb-24 5:19 
GeneralRe: How to recover missing file ? Pin
jschell29-Feb-24 12:24
jschell29-Feb-24 12:24 
GeneralRe: How to recover missing file ? Pin
k505429-Feb-24 12:50
mvek505429-Feb-24 12:50 
QuestionMpi blocking communication Pin
Member 1518121126-Feb-24 11:19
Member 1518121126-Feb-24 11:19 
AnswerRe: Mpi blocking communication Pin
jschell26-Feb-24 12:22
jschell26-Feb-24 12:22 
Questionhow to "include" this... Pin
Salvatore Terress26-Feb-24 8:37
Salvatore Terress26-Feb-24 8:37 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.