Click here to Skip to main content
15,918,624 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Unresolved extern "dwTlsIndex" exported function in dll Pin
CPallini17-Sep-19 3:19
mveCPallini17-Sep-19 3:19 
GeneralRe: Unresolved extern "dwTlsIndex" exported function in dll Pin
ForNow17-Sep-19 3:42
ForNow17-Sep-19 3:42 
GeneralRe: Unresolved extern "dwTlsIndex" exported function in dll Changed DLLMAIN.CPP to DLLMAIN.C clean link Pin
ForNow17-Sep-19 8:02
ForNow17-Sep-19 8:02 
Questionmanual kerning with winAPI Pin
Alexander Kindel15-Sep-19 21:38
Alexander Kindel15-Sep-19 21:38 
Questiontypedef for a function for different platforms Pin
ForNow13-Sep-19 3:29
ForNow13-Sep-19 3:29 
AnswerRe: typedef for a function for different platforms Pin
Stefan_Lang13-Sep-19 3:58
Stefan_Lang13-Sep-19 3:58 
GeneralRe: typedef for a function for different platforms Pin
ForNow13-Sep-19 4:36
ForNow13-Sep-19 4:36 
AnswerRe: typedef for a function for different platforms Pin
Richard MacCutchan13-Sep-19 3:59
mveRichard MacCutchan13-Sep-19 3:59 
GeneralRe: typedef for a function for different platforms Pin
ForNow13-Sep-19 4:36
ForNow13-Sep-19 4:36 
QuestionError 12029 WinHTTP Pin
Diprom12-Sep-19 22:36
Diprom12-Sep-19 22:36 
AnswerRe: Error 12029 WinHTTP Pin
Richard MacCutchan13-Sep-19 1:16
mveRichard MacCutchan13-Sep-19 1:16 
AnswerRe: Error 12029 WinHTTP Pin
Victor Nijegorodov13-Sep-19 2:26
Victor Nijegorodov13-Sep-19 2:26 
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 

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.