Click here to Skip to main content
15,896,429 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Error 12029 WinHTTP Pin
Diprom13-Sep-19 2:30
Diprom13-Sep-19 2:30 
GeneralRe: Error 12029 WinHTTP Pin
Victor Nijegorodov13-Sep-19 2:38
Victor Nijegorodov13-Sep-19 2:38 
AnswerRe: Error 12029 WinHTTP Pin
Randor 14-Sep-19 3:03
professional Randor 14-Sep-19 3:03 
QuestionVisual Studio 2017 C++ Static analyzer (or in ReSharper C++) Pin
Maximilien12-Sep-19 4:21
Maximilien12-Sep-19 4:21 
AnswerRe: Visual Studio 2017 C++ Static analyzer (or in ReSharper C++) Pin
Stefan_Lang12-Sep-19 5:33
Stefan_Lang12-Sep-19 5:33 
AnswerRe: Visual Studio 2017 C++ Static analyzer (or in ReSharper C++) Pin
CPallini12-Sep-19 21:08
mveCPallini12-Sep-19 21:08 
GeneralRe: Visual Studio 2017 C++ Static analyzer (or in ReSharper C++) Pin
Stefan_Lang12-Sep-19 22:19
Stefan_Lang12-Sep-19 22:19 
GeneralRe: Visual Studio 2017 C++ Static analyzer (or in ReSharper C++) Pin
Stefan_Lang12-Sep-19 23:26
Stefan_Lang12-Sep-19 23:26 
Ok, I'll add some more mystery. Here's my take:
C++
#include <iostream>
using namespace std;
class Loo
{
public:
    static int x;
    static int y;
    static int z;
    int a;
    int b = ++y;
    int c;
    Loo() : a(++x), c(b+(++z)) {}
    Loo(int i) : a(++b), b(++i), c(++b) {}
    void show(){ cout << "a " << a << ", b " << b << ", c " << c << endl;}
    static void show_(){ cout << "x " << x << ", y " << y << ", z " << z << endl;}
};
int Loo::x = 0;
int Loo::y = 0;
int Loo::z = 0;
int main()
{
  Loo::show_();
  Loo l;
  l.show();
  Loo::show_();
  Loo l5(5);
  l5.show();
  Loo::show_();
  return 0;
}
And the output I get is:
x 0, y 0, z 0                                                                                          
a 1, b 1, c 2                                                                                          
x 1, y 1, z 1                                                                                          
a 1, b 7, c 7                                                                                          
x 1, y 1, z 1
The first two lines are unspectactular: they show what can be expected from the code.

The third line is also unsurprising. Importantly, it shows that the member initialization of b was invoked by the default constructor (y=1).

The fourth line however is very odd: It starts with a=1. How? Let's take apart the commonly known rules on initilization order: the initializer list gets processed left to right for all virtual base classes, than all base classes, then all members. We only have members, so initialization order is a, then b, then c.

Next, according to this site Non-static data members - cppreference.com[^] the non-static member initialization of b gets skipped, because b is on the initalizer list. This means, b is not initialized at all by the time a is getting initialized! Note that y remains unchanged, proving that the member initializer is not invoked! Therefore the value assigned to a is undefined. As it seems, in this case b assumes a value of 0, incremented to 1, and then assigned to a.

Next, b gets initialized. It's value is based on i, which is 5, so the value of b should be 6. The output shows 7 - but let's look further: we still have to initialize c, which again is based b, incrementing it. Therefore b is now 7, and c too.

Ok, all is well, except that the value of a is undefined, even though b appears to be initialized in two places! Only that one initialization is skipped because of the other that is happening too late Dead | X|
GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)

AnswerRe: Visual Studio 2017 C++ Static analyzer (or in ReSharper C++) Pin
Stefan_Lang12-Sep-19 22:46
Stefan_Lang12-Sep-19 22:46 
QuestionMFC VC++ ListCtrl Pin
Member 1457555612-Sep-19 1:23
Member 1457555612-Sep-19 1:23 
AnswerRe: MFC VC++ ListCtrl Pin
CPallini12-Sep-19 1:32
mveCPallini12-Sep-19 1:32 
GeneralRe: MFC VC++ ListCtrl Pin
Member 1457555612-Sep-19 1:41
Member 1457555612-Sep-19 1:41 
GeneralRe: MFC VC++ ListCtrl Pin
Richard MacCutchan12-Sep-19 1:45
mveRichard MacCutchan12-Sep-19 1:45 
AnswerRe: MFC VC++ ListCtrl Pin
Victor Nijegorodov12-Sep-19 1:41
Victor Nijegorodov12-Sep-19 1:41 
QuestionRe: MFC VC++ ListCtrl Pin
David Crow12-Sep-19 7:26
David Crow12-Sep-19 7:26 
Questionfast return of data to the server Pin
Diprom11-Sep-19 22:36
Diprom11-Sep-19 22:36 
AnswerRe: fast return of data to the server Pin
Diprom11-Sep-19 23:11
Diprom11-Sep-19 23:11 
GeneralRe: fast return of data to the server Pin
Stefan_Lang12-Sep-19 6:02
Stefan_Lang12-Sep-19 6:02 
QuestionVirtual address of pointer keeps changing Pin
Rakanoth9-Sep-19 22:45
Rakanoth9-Sep-19 22:45 
AnswerRe: Virtual address of pointer keeps changing Pin
Richard MacCutchan9-Sep-19 23:18
mveRichard MacCutchan9-Sep-19 23:18 
GeneralRe: Virtual address of pointer keeps changing Pin
Rakanoth10-Sep-19 2:28
Rakanoth10-Sep-19 2:28 
GeneralRe: Virtual address of pointer keeps changing Pin
OriginalGriff10-Sep-19 2:29
mveOriginalGriff10-Sep-19 2:29 
GeneralRe: Virtual address of pointer keeps changing Pin
Rakanoth10-Sep-19 2:48
Rakanoth10-Sep-19 2:48 
GeneralRe: Virtual address of pointer keeps changing Pin
OriginalGriff10-Sep-19 3:04
mveOriginalGriff10-Sep-19 3:04 
AnswerRe: Virtual address of pointer keeps changing Pin
Stefan_Lang10-Sep-19 3:24
Stefan_Lang10-Sep-19 3:24 

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.