Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #47469 > unrolled thread
| Started by | Popping mad <rainbow@colition.gov> |
|---|---|
| First post | 2016-12-21 11:16 +0000 |
| Last post | 2016-12-21 14:24 -0500 |
| Articles | 6 — 5 participants |
Back to article view | Back to comp.lang.c++
initiation string not doing as I expected Popping mad <rainbow@colition.gov> - 2016-12-21 11:16 +0000
Re: initiation string not doing as I expected Paavo Helde <myfirstname@osa.pri.ee> - 2016-12-21 13:50 +0200
Re: initiation string not doing as I expected "Fred.Zwarts" <F.Zwarts@KVI.nl> - 2016-12-21 13:47 +0100
Re: initiation string not doing as I expected "Fred.Zwarts" <F.Zwarts@KVI.nl> - 2016-12-21 13:51 +0100
Re: initiation string not doing as I expected Öö Tiib <ootiib@hot.ee> - 2016-12-21 13:40 -0800
Re: initiation string not doing as I expected ruben safir <ruben@mrbrklyn.com> - 2016-12-21 14:24 -0500
| From | Popping mad <rainbow@colition.gov> |
|---|---|
| Date | 2016-12-21 11:16 +0000 |
| Subject | initiation string not doing as I expected |
| Message-ID | <o3doas$1pf$1@reader1.panix.com> |
Why is canvas_index not being assigned properly in the initiation list
unless I do an assignment inside the backets
/*
*
=====================================================================================
*
* Filename: test.cpp
*
* Description: Threading Experiment
*
* Version: 1.0
* Created: 12/18/2016 12:46:51 PM
* Revision: none
* Compiler: gcc
*
* Author: Ruben Safir (mn), ruben@mrbrklyn.com
* Company: NYLXS Inc
*
*
=====================================================================================
*/
#include <iostream>
#include <thread>
namespace testing{
std::thread t[10];
class PIC
{
public:
PIC():beg{&source[0]}, end{&source[99]} , canvas_index
{canvas}
{
canvas_index = canvas;
for(int i = 0; i < 10;i++)
{
t[i] = std::thread([this]{ readin(beg); }
);
std::cout << i << ": Making a thread" <<
std::endl;
beg += 10;
}
};
~PIC()
{
std::cout << "In the destructor" << std::endl;
for(int i=0; i<10; i++)
{
t[i].join();
std::cout << i << ": Joining a thread" <<
std::endl;
}
};
void readin(char * start)
{
for( int i = 0; i<10; i++ )
{
*canvas_index = *start;
std::cout << i << ": Copy " <<
reinterpret_cast<char>(*start) << std::endl;
std::cout << i << ": Copied to
canvas_index " << reinterpret_cast<char>(*canvas_index) << std::endl;
canvas_index++;
start++;
}
};
char * get_canvas()
{
return canvas;
}
private:
char * beg;
char * end;
char * canvas_index;
char * canvas = new char[100];
char source[100] = {
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'
};
//int index;
};
}//end namespace
int main(int argc, char** argv)
{
testing::PIC fido;
for(int i = 0; i<100;i++)
{
std::cout << i << " Canvas Position " << fido.get_canvas()
[i] << std::endl;
}
return 0;
}
[toc] | [next] | [standalone]
| From | Paavo Helde <myfirstname@osa.pri.ee> |
|---|---|
| Date | 2016-12-21 13:50 +0200 |
| Message-ID | <O5mdnY-xfJ0S8cfFnZ2dnUU78IvNnZ2d@giganews.com> |
| In reply to | #47469 |
On 21.12.2016 13:16, Popping mad wrote:
> Why is canvas_index not being assigned properly in the initiation list
> unless I do an assignment inside the backets
>
> class PIC
> {
> public:
> PIC():beg{&source[0]}, end{&source[99]} , canvas_index
> {canvas}
> {
[...]
> };
[...]
> private:
[...]
> char * canvas_index;
> char * canvas = new char[100];
[...]
canvas_index is initialized before canvas, because it is declared before
canvas in the class definition. Thus, it is initialized with garbage.
[toc] | [prev] | [next] | [standalone]
| From | "Fred.Zwarts" <F.Zwarts@KVI.nl> |
|---|---|
| Date | 2016-12-21 13:47 +0100 |
| Message-ID | <o3dtkv$1goc$1@gioia.aioe.org> |
| In reply to | #47470 |
"Paavo Helde" schreef in bericht
news:O5mdnY-xfJ0S8cfFnZ2dnUU78IvNnZ2d@giganews.com...
>
>On 21.12.2016 13:16, Popping mad wrote:
>> Why is canvas_index not being assigned properly in the initiation list
>> unless I do an assignment inside the backets
>>
>> class PIC
>> {
>> public:
>> PIC():beg{&source[0]}, end{&source[99]} , canvas_index
>> {canvas}
>> {
>[...]
>> };
>[...]
>> private:
>[...]
>> char * canvas_index;
>> char * canvas = new char[100];
>[...]
>
>canvas_index is initialized before canvas, because it is declared before
>canvas in the class definition. Thus, it is initialized with garbage.
The compilers I use, issue a warning if the order of the initializations is
different from the order of the declarations. I wonder which compiler was
used, that did not warn.
[toc] | [prev] | [next] | [standalone]
| From | "Fred.Zwarts" <F.Zwarts@KVI.nl> |
|---|---|
| Date | 2016-12-21 13:51 +0100 |
| Message-ID | <o3dtsb$1h35$1@gioia.aioe.org> |
| In reply to | #47472 |
"Fred.Zwarts" schreef in bericht news:o3dtkv$1goc$1@gioia.aioe.org...
>
>"Paavo Helde" schreef in bericht
>news:O5mdnY-xfJ0S8cfFnZ2dnUU78IvNnZ2d@giganews.com...
>>
>>On 21.12.2016 13:16, Popping mad wrote:
>>> Why is canvas_index not being assigned properly in the initiation list
>>> unless I do an assignment inside the backets
>>>
>>> class PIC
>>> {
>>> public:
>>> PIC():beg{&source[0]}, end{&source[99]} , canvas_index
>>> {canvas}
>>> {
>>[...]
>>> };
>>[...]
>>> private:
>>[...]
>>> char * canvas_index;
>>> char * canvas = new char[100];
>>[...]
>>
>>canvas_index is initialized before canvas, because it is declared before
>>canvas in the class definition. Thus, it is initialized with garbage.
>
>The compilers I use, issue a warning if the order of the initializations is
>different from the order of the declarations. I wonder which compiler was
>used, that did not warn.
Probably, my reaction was too fast. I now see that canvas is not initialized
in the initialization list, so that the compiler cannot detect the
non-matching order easily.
[toc] | [prev] | [next] | [standalone]
| From | Öö Tiib <ootiib@hot.ee> |
|---|---|
| Date | 2016-12-21 13:40 -0800 |
| Message-ID | <a6ecb714-df32-4581-8fb3-a4796329a888@googlegroups.com> |
| In reply to | #47473 |
On Wednesday, 21 December 2016 14:51:32 UTC+2, F.Zwarts wrote: > "Fred.Zwarts" schreef in bericht news:o3dtkv$1goc$1@gioia.aioe.org... > > > > > >The compilers I use, issue a warning if the order of the initializations is > >different from the order of the declarations. I wonder which compiler was > >used, that did not warn. > > Probably, my reaction was too fast. I now see that canvas is not initialized > in the initialization list, so that the compiler cannot detect the > non-matching order easily. clang still warns there about uninitialized canvas used to initialize canvas_index.
[toc] | [prev] | [next] | [standalone]
| From | ruben safir <ruben@mrbrklyn.com> |
|---|---|
| Date | 2016-12-21 14:24 -0500 |
| Message-ID | <o3ektr$b1d$1@reader1.panix.com> |
| In reply to | #47470 |
On 12/21/2016 06:50 AM, Paavo Helde wrote: > canvas_index is initialized before canvas, because it is declared before > canvas in the class definition. Thus, it is initialized with garbage. thanks.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.c++
csiph-web