Thu Nov 21 23:28:21 2024
EVENTS
 FREE
SOFTWARE
INSTITUTE

POLITICS
JOBS
MEMBERS'
CORNER

MAILING
LIST

NYLXS Mailing Lists and Archives
NYLXS Members have a lot to say and share but we don't keep many secrets. Join the Hangout Mailing List and say your peice.

DATE 2016-11-01

LEARN

2024-11-21 | 2024-10-21 | 2024-09-21 | 2024-08-21 | 2024-07-21 | 2024-06-21 | 2024-05-21 | 2024-04-21 | 2024-03-21 | 2024-02-21 | 2024-01-21 | 2023-12-21 | 2023-11-21 | 2023-10-21 | 2023-09-21 | 2023-08-21 | 2023-07-21 | 2023-06-21 | 2023-05-21 | 2023-04-21 | 2023-03-21 | 2023-02-21 | 2023-01-21 | 2022-12-21 | 2022-11-21 | 2022-10-21 | 2022-09-21 | 2022-08-21 | 2022-07-21 | 2022-06-21 | 2022-05-21 | 2022-04-21 | 2022-03-21 | 2022-02-21 | 2022-01-21 | 2021-12-21 | 2021-11-21 | 2021-10-21 | 2021-09-21 | 2021-08-21 | 2021-07-21 | 2021-06-21 | 2021-05-21 | 2021-04-21 | 2021-03-21 | 2021-02-21 | 2021-01-21 | 2020-12-21 | 2020-11-21 | 2020-10-21 | 2020-09-21 | 2020-08-21 | 2020-07-21 | 2020-06-21 | 2020-05-21 | 2020-04-21 | 2020-03-21 | 2020-02-21 | 2020-01-21 | 2019-12-21 | 2019-11-21 | 2019-10-21 | 2019-09-21 | 2019-08-21 | 2019-07-21 | 2019-06-21 | 2019-05-21 | 2019-04-21 | 2019-03-21 | 2019-02-21 | 2019-01-21 | 2018-12-21 | 2018-11-21 | 2018-10-21 | 2018-09-21 | 2018-08-21 | 2018-07-21 | 2018-06-21 | 2018-05-21 | 2018-04-21 | 2018-03-21 | 2018-02-21 | 2018-01-21 | 2017-12-21 | 2017-11-21 | 2017-10-21 | 2017-09-21 | 2017-08-21 | 2017-07-21 | 2017-06-21 | 2017-05-21 | 2017-04-21 | 2017-03-21 | 2017-02-21 | 2017-01-21 | 2016-12-21 | 2016-11-21 | 2016-10-21 | 2016-09-21 | 2016-08-21 | 2016-07-21 | 2016-06-21 | 2016-05-21 | 2016-04-21 | 2016-03-21 | 2016-02-21 | 2016-01-21 | 2015-12-21 | 2015-11-21 | 2015-10-21 | 2015-09-21 | 2015-08-21 | 2015-07-21 | 2015-06-21 | 2015-05-21 | 2015-04-21 | 2015-03-21 | 2015-02-21 | 2015-01-21 | 2014-12-21 | 2014-11-21 | 2014-10-21

Key: Value:

Key: Value:

MESSAGE
DATE 2016-11-21
FROM ruben safir
SUBJECT Subject: [Learn] Fwd: hidden static
From learn-bounces-at-nylxs.com Mon Nov 21 15:52:12 2016
Return-Path:
X-Original-To: archive-at-mrbrklyn.com
Delivered-To: archive-at-mrbrklyn.com
Received: from www.mrbrklyn.com (www.mrbrklyn.com [96.57.23.82])
by mrbrklyn.com (Postfix) with ESMTP id D276A161314;
Mon, 21 Nov 2016 15:52:11 -0500 (EST)
X-Original-To: learn-at-nylxs.com
Delivered-To: learn-at-nylxs.com
Received: from [10.0.0.62] (flatbush.mrbrklyn.com [10.0.0.62])
by mrbrklyn.com (Postfix) with ESMTP id 66268161312
for ; Mon, 21 Nov 2016 15:52:09 -0500 (EST)
References:




<20161121144815.63a2899c-at-dell.homenet> <20161121173103.17c0ed02-at-dell.homenet>
<20161121181806.58043cf8-at-dell.homenet>
To: learn-at-nylxs.com
From: ruben safir
X-Forwarded-Message-Id:





<20161121144815.63a2899c-at-dell.homenet> <20161121173103.17c0ed02-at-dell.homenet>
<20161121181806.58043cf8-at-dell.homenet>
Message-ID: <98fa3748-b6c8-999c-5105-fc72190b6375-at-mrbrklyn.com>
Date: Mon, 21 Nov 2016 15:52:09 -0500
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.4.0
MIME-Version: 1.0
In-Reply-To: <20161121181806.58043cf8-at-dell.homenet>
Content-Type: multipart/mixed; boundary="------------FFF26FD058A6765DB3A66A85"
Subject: [Learn] Fwd: hidden static
X-BeenThere: learn-at-nylxs.com
X-Mailman-Version: 2.1.17
Precedence: list
List-Id:
List-Unsubscribe: ,

List-Archive:
List-Post:
List-Help:
List-Subscribe: ,

Errors-To: learn-bounces-at-nylxs.com
Sender: "Learn"

This is a multi-part message in MIME format.
--------------FFF26FD058A6765DB3A66A85
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit

C++ static variables --

--------------FFF26FD058A6765DB3A66A85
Content-Type: message/rfc822;
name="hidden static.eml"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename="hidden static.eml"

Path: reader2.panix.com!panix!not-for-mail
From: Popping mad
Newsgroups: comp.lang.c++
Subject: hidden static
Date: Sat, 19 Nov 2016 01:49:12 +0000 (UTC)
Organization: PANIX Public Access Internet and UNIX, NYC
Message-ID:
NNTP-Posting-Host: www.mrbrklyn.com
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: reader2.panix.com 1479520152 17183 96.57.23.82 (19 Nov 2016 01:49:12 GMT)
X-Complaints-To: abuse-at-panix.com
NNTP-Posting-Date: Sat, 19 Nov 2016 01:49:12 +0000 (UTC)
User-Agent: Pan/0.140 (Chocolate Salty Balls; GIT b8fc14e
git.gnome.org/git/pan2)
Xref: panix comp.lang.c++:1125334

I've a declared static as a public member of an
object but it doesn't seem to show up in the compiler

/home/ruben/src/test_static/test.cpp|22| undefined reference to `blah::A::here'


If I put it on top it errors are a private member. When I move it
to public, it is not being seen

The three test case files look like this


test.cpp

18 #include "test.h"
19 #include
20 namespace blah{
21 void A::read(int in){
22 A::here = in;
23 std::cout << here << std::endl;
24 }
25 }


test.h

1 namespace blah{
2 class A{
3 public:
4 static int here;
5 A(int in=0){
6 here = in;
7 };
8 void read(int);
9 };
10
11 }
~

main.cpp
18 #include "test.h"
19 #include
20 namespace std{
21
22 int main(int argc, char** argv){
23
24 blah::A* a = new blah::A{9};
25 cout << a->here << endl;
26 return 0;
27 }
28
29 }
~
makefile

1 CXX:=g++
2 CXXFLAGS:=-Wall -ggdb -pg -pthread
3
4 LDFLAGS:=-L/usr/local/lib/mysql -lmysqlpp -lmysqlclient
5
6 test : test.o main.o
7 ${CXX} ${CXXFLAGS} -o testme test.o main.o
8
9 main.o : main.cpp
10 ${CXX} ${CXXFLAGS} -o main.o -c main.cpp
11
12 test.o : test.cpp test.h
13 ${CXX} ${CXXFLAGS} -c test.cpp
14
15 clean :
16 rm testme *.o make.deps
17 touch *.cpp *.h
18
19 include make.deps
20 make.deps: *.cpp ; gcc -M *.cpp >$-at-
~

I need an extern?
1 || g++ -Wall -ggdb -pg -pthread -o testme test.o main.o
2 || /usr/lib/gcc/x86_64-pc-linux-gnu/6.2.1/../../../../lib/gcrt1.o: In function `_start':
3 || (.text+0x20): undefined reference to `main'
4 || test.o: In function `blah::A::read(int)':
5 /home/ruben/src/test_static/test.cpp|22| undefined reference to `blah::A::here'
6 /home/ruben/src/test_static/test.cpp|23| undefined reference to `blah::A::here'
7 || main.o: In function `std::main(int, char**)':
8 /home/ruben/src/test_static/main.cpp|25| undefined reference to `blah::A::here'
9 || main.o: In function `blah::A::A(int)':
10 /home/ruben/src/test_static/test.h|6| undefined reference to `blah::A::here'

--------------FFF26FD058A6765DB3A66A85
Content-Type: message/rfc822;
name="Re: hidden static.eml"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename="Re: hidden static.eml"

Path: reader2.panix.com!panix!goblin2!goblin1!goblin.stu.neva.ru!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: Ian Collins
Newsgroups: comp.lang.c++
Subject: Re: hidden static
Date: Sat, 19 Nov 2016 16:07:01 +1300
Message-ID:
References:
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: individual.net +iTYoWlqtAMDes8BxMG/tgguX4gbR1m7ps3eeKYPyQQeA2t6ol
Cancel-Lock: sha1:zkBTSQKoPtOuqGD2BtJcB3Qke60=
User-Agent: Mozilla/5.0 (X11; SunOS i86pc; rv:38.0) Gecko/20100101
Thunderbird/38.5.1
In-Reply-To:
Xref: panix comp.lang.c++:1125336

On 11/19/16 02:49 PM, Popping mad wrote:
> I've a declared static as a public member of an
> object but it doesn't seem to show up in the compiler
>
> /home/ruben/src/test_static/test.cpp|22| undefined reference to `blah::A::here'
>
>
> If I put it on top it errors are a private member. When I move it
> to public, it is not being seen
>
> The three test case files look like this
>
>
> test.cpp
>
> 18 #include "test.h"
> 19 #include
> 20 namespace blah{
> 21 void A::read(int in){
> 22 A::here = in;
> 23 std::cout << here << std::endl;
> 24 }
> 25 }
>
>
> test.h
>
> 1 namespace blah{
> 2 class A{
> 3 public:
> 4 static int here;
> 5 A(int in=0){
> 6 here = in;
> 7 };
> 8 void read(int);
> 9 };
> 10
> 11 }

Who have declared A::here, but you haven't defined it anywhere.

--
Ian

--------------FFF26FD058A6765DB3A66A85
Content-Type: message/rfc822;
name="Re: hidden static.eml"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename="Re: hidden static.eml"

Path: reader2.panix.com!panix!goblin3!goblin2!goblin1!goblin.stu.neva.ru!border1.nntp.ams1.giganews.com!nntp.giganews.com!buffer1.nntp.ams1.giganews.com!buffer2.nntp.ams1.giganews.com!news.giganews.com.POSTED!not-for-mail
NNTP-Posting-Date: Sat, 19 Nov 2016 02:30:11 -0600
Date: Sat, 19 Nov 2016 10:30:14 +0200
From: Paavo Helde
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:25.8) Gecko/20151117 FossaMail/25.1.9
MIME-Version: 1.0
Newsgroups: comp.lang.c++
Subject: Re: hidden static
References:
In-Reply-To:
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Message-ID:
X-Usenet-Provider: http://www.giganews.com
X-Trace: sv3-903oDxr+2ADw8BBbVs2Wz3ceC59ib5ESQIqatdjeszyty77md085+f0YNVQKAaL7m1tFJCAWWD6TXLW!u5UoeRYBUd4cgymY33AvbxrQMTVlSeIibymaV9cO7oX2EamuJ89UeI7sVRHPM+codf4cZZFYFms=
X-Complaints-To: abuse-at-giganews.com
X-DMCA-Notifications: http://www.giganews.com/info/dmca.html
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly
X-Postfilter: 1.3.40
X-Original-Bytes: 1503
Xref: panix comp.lang.c++:1125337

On 19.11.2016 3:49, Popping mad wrote:
> I've a declared static as a public member of an
> object but it doesn't seem to show up in the compiler
>
> /home/ruben/src/test_static/test.cpp|22| undefined reference to `blah::A::here'

See https://isocpp.org/wiki/faq/ctors#link-errs-static-data-mems

While there, consider reading the whole https://isocpp.org/faq




--------------FFF26FD058A6765DB3A66A85
Content-Type: message/rfc822;
name="Re: hidden static.eml"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename="Re: hidden static.eml"

Path: reader2.panix.com!panix!not-for-mail
From: Popping mad
Newsgroups: comp.lang.c++
Subject: Re: hidden static
Date: Sat, 19 Nov 2016 17:01:03 +0000 (UTC)
Organization: PANIX Public Access Internet and UNIX, NYC
Message-ID:
References:

NNTP-Posting-Host: www.mrbrklyn.com
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: reader2.panix.com 1479574863 17183 96.57.23.82 (19 Nov 2016 17:01:03 GMT)
X-Complaints-To: abuse-at-panix.com
NNTP-Posting-Date: Sat, 19 Nov 2016 17:01:03 +0000 (UTC)
User-Agent: Pan/0.140 (Chocolate Salty Balls; GIT b8fc14e
git.gnome.org/git/pan2)
Xref: panix comp.lang.c++:1125342

On Sat, 19 Nov 2016 10:30:14 +0200, Paavo Helde wrote:

> See https://isocpp.org/wiki/faq/ctors#link-errs-static-data-mems
>
> While there, consider reading the whole https://isocpp.org/faq


This is an excellent explanation, but I'm still not clear on this. I
think it is saying that a static has to be declared and defined within a
compilational unit. I'm not sure why, though. And I've asked before,
and read, but I'm still not clear on what a compilation unit is.


--------------FFF26FD058A6765DB3A66A85
Content-Type: message/rfc822;
name="Re: hidden static.eml"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename="Re: hidden static.eml"

Path: reader2.panix.com!panix!goblin2!goblin1!goblin.stu.neva.ru!border1.nntp.ams1.giganews.com!nntp.giganews.com!buffer1.nntp.ams1.giganews.com!news.giganews.com.POSTED!not-for-mail
NNTP-Posting-Date: Sat, 19 Nov 2016 16:12:33 -0600
Date: Sun, 20 Nov 2016 00:12:36 +0200
From: Paavo Helde
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:25.8) Gecko/20151117 FossaMail/25.1.9
MIME-Version: 1.0
Newsgroups: comp.lang.c++
Subject: Re: hidden static
References:
In-Reply-To:
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Message-ID:
X-Usenet-Provider: http://www.giganews.com
X-Trace: sv3-5Y0ca5EXbUi1Ofd9NOQ7/KALrzYewxQOY1KKx+9Sv3gUeMq2wkBv4dAEdpT3bxMO5lJTn5lGmzP4IzY!mUAcuwRUtXz1lofm+Vu09FPPm44+L4MWY2OB/rCiaLJZ24jkkzEDQTl9C36LmnAQMPYxYxCbG/Y=
X-Complaints-To: abuse-at-giganews.com
X-DMCA-Notifications: http://www.giganews.com/info/dmca.html
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly
X-Postfilter: 1.3.40
X-Original-Bytes: 2479
Xref: panix comp.lang.c++:1125350

On 19.11.2016 19:01, Popping mad wrote:
> On Sat, 19 Nov 2016 10:30:14 +0200, Paavo Helde wrote:
>
>> See https://isocpp.org/wiki/faq/ctors#link-errs-static-data-mems
>>
>> While there, consider reading the whole https://isocpp.org/faq
>
>
> This is an excellent explanation, but I'm still not clear on this. I
> think it is saying that a static has to be declared and defined within a
> compilational unit. I'm not sure why, though.

There are other things in C++ which are declared in a header file and
then defined in some translation unit. The prime example are functions
(member and non-member). That's just the way how C++ does things.

When defining a class static member in some cpp file, one tells the
compiler to reserve memory for it in an the data segment of this
translation unit, plus one also specifies the arguments instructing the
compiler how to construct it.

However, for some simpler scenarios the initialization of the class
static member can be written directly in the declaration, which is
probably the most confusing point here.

> And I've asked before,
> and read, but I'm still not clear on what a compilation unit is.

It is just whatever is compiled into a single object .o/.obj file.

hth
Paavo


--------------FFF26FD058A6765DB3A66A85
Content-Type: message/rfc822;
name="Re: hidden static.eml"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename="Re: hidden static.eml"

Path: reader2.panix.com!panix!goblin3!goblin.stu.neva.ru!news.netfront.net!.POSTED.217.30.184.161!not-for-mail
From: Juha Nieminen
Newsgroups: comp.lang.c++
Subject: Re: hidden static
Date: Mon, 21 Nov 2016 07:52:39 +0000 (UTC)
Organization: Netfront http://www.netfront.net/
Message-ID:
References:
Injection-Date: Mon, 21 Nov 2016 07:52:39 +0000 (UTC)
Injection-Info: adenine.netfront.net; posting-host="217.30.184.161";
logging-data="34748"; mail-complaints-to="news-at-netfront.net"
User-Agent: tin/2.2.1-20140504 ("Tober an Righ") (UNIX) (Linux/3.14.79-grbfs-kapsi (x86_64))
Xref: panix comp.lang.c++:1125395

Popping mad wrote:
> This is an excellent explanation, but I'm still not clear on this. I
> think it is saying that a static has to be declared and defined within a
> compilational unit. I'm not sure why, though. And I've asked before,
> and read, but I'm still not clear on what a compilation unit is.

A static member variable needs to exist somewhere in the executable
(because, among other things, you need to be able to eg. have a pointer
pointing to it). You have to tell the compiler which compilation unit
(in practice which object file) the actual instance of that variable is.
The compiler won't guess; you need to tell it explicitly where it should
be put.

(Incidentally, C++17 will introduce the concept of inline variables,
which will allow you to define static member variables in the header
file itself, causing the linker to merge all the instantiations into
one. But that will be available only after compilers start supporting
it.)

--------------FFF26FD058A6765DB3A66A85
Content-Type: message/rfc822;
name="Re: hidden static.eml"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename="Re: hidden static.eml"

Path: reader2.panix.com!panix!goblin2!goblin.stu.neva.ru!peer02.am4!peer.am4.highwinds-media.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!post02.iad.highwinds-media.com!fx34.iad.POSTED!not-for-mail
X-Newsreader: xrn 9.03-beta-14-64bit
Sender: scott-at-dragon.sl.home (Scott Lurndal)
From: scott-at-slp53.sl.home (Scott Lurndal)
Reply-To: slp53-at-pacbell.net
Subject: Re: hidden static
Newsgroups: comp.lang.c++
References:
Message-ID:
X-Complaints-To: abuse-at-usenetserver.com
NNTP-Posting-Date: Mon, 21 Nov 2016 13:26:07 UTC
Organization: UsenetServer - www.usenetserver.com
Date: Mon, 21 Nov 2016 13:26:07 GMT
X-Received-Body-CRC: 1994721708
X-Received-Bytes: 1585
Xref: panix comp.lang.c++:1125403

Juha Nieminen writes:
>Popping mad wrote:
>> This is an excellent explanation, but I'm still not clear on this. I
>> think it is saying that a static has to be declared and defined within a
>> compilational unit. I'm not sure why, though. And I've asked before,
>> and read, but I'm still not clear on what a compilation unit is.
>
>A static member variable needs to exist somewhere in the executable
>(because, among other things, you need to be able to eg. have a pointer
>pointing to it).

The confusing part for some folks is that gcc/binutils, when using -O3, won't
require the definition unless the address of the static const value
is taken. Remove -O3 and you'll start getting link errors.

--------------FFF26FD058A6765DB3A66A85
Content-Type: message/rfc822;
name="Re: hidden static.eml"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename="Re: hidden static.eml"

Path: reader2.panix.com!panix!goblin2!goblin1!goblin.stu.neva.ru!border1.nntp.ams1.giganews.com!nntp.giganews.com!buffer1.nntp.ams1.giganews.com!nntp.brightview.co.uk!news.brightview.co.uk.POSTED!not-for-mail
NNTP-Posting-Date: Mon, 21 Nov 2016 08:48:30 -0600
Date: Mon, 21 Nov 2016 14:48:15 +0000
From: Chris Vine
Newsgroups: comp.lang.c++
Subject: Re: hidden static
Message-ID: <20161121144815.63a2899c-at-dell.homenet>
References:




X-Newsreader: Claws Mail 3.13.2 (GTK+ 2.24.31; x86_64-unknown-linux-gnu)
MIME-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
X-Usenet-Provider: http://www.giganews.com
X-Trace: sv3-w23lfhOSTorUVxFJLxf9GJg1mUExKYcD2Xk+4+sbdp5V3lpWUJhhVbK9gPcC7+oxblQ7q5+aeOZgYc2!0+6DIetz8FWHSoHw+gggdCyZb2FNzSyHzu1tn9kx/qAAT8sdbrcMPN/2xbnPjX6tcPA+GNMSXxSU!RDVnGOyi
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly
X-Postfilter: 1.3.40
X-Original-Bytes: 2575
Xref: panix comp.lang.c++:1125407

On Mon, 21 Nov 2016 13:26:07 GMT
scott-at-slp53.sl.home (Scott Lurndal) wrote:
> Juha Nieminen writes:
> >Popping mad wrote:
> >> This is an excellent explanation, but I'm still not clear on
> >> this. I think it is saying that a static has to be declared and
> >> defined within a compilational unit. I'm not sure why, though.
> >> And I've asked before, and read, but I'm still not clear on what a
> >> compilation unit is.
> >
> >A static member variable needs to exist somewhere in the executable
> >(because, among other things, you need to be able to eg. have a
> >pointer pointing to it).
>
> The confusing part for some folks is that gcc/binutils, when using
> -O3, won't require the definition unless the address of the static
> const value is taken. Remove -O3 and you'll start getting link
> errors.

My recollection in the case of the declaration of a const static
integer member variable (typically with a literal value) is that you
don't need to provide a definition for it if it is not ODR-used,
whatever the optimization level. Taking an address is one way of
ODR-using it. Casting it to lvalue of another type is another. I don't
at the moment have the C++ standard in front of me to give you the
reference.

These days I guess you would probably declare such a static member
variable constexpr rather than const anyway.

--------------FFF26FD058A6765DB3A66A85
Content-Type: message/rfc822;
name="Re: hidden static.eml"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename="Re: hidden static.eml"

Path: reader2.panix.com!panix!bloom-beacon.mit.edu!bloom-beacon.mit.edu!168.235.88.217.MISMATCH!2.us.feeder.erje.net!feeder.erje.net!2.eu.feeder.erje.net!border1.nntp.ams1.giganews.com!border2.nntp.ams1.giganews.com!nntp.giganews.com!buffer2.nntp.ams1.giganews.com!nntp.brightview.co.uk!news.brightview.co.uk.POSTED!not-for-mail
NNTP-Posting-Date: Mon, 21 Nov 2016 11:31:15 -0600
Date: Mon, 21 Nov 2016 17:31:03 +0000
From: Chris Vine
Newsgroups: comp.lang.c++
Subject: Re: hidden static
Message-ID: <20161121173103.17c0ed02-at-dell.homenet>
References:




<20161121144815.63a2899c-at-dell.homenet>
X-Newsreader: Claws Mail 3.13.2 (GTK+ 2.24.31; x86_64-unknown-linux-gnu)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
X-Usenet-Provider: http://www.giganews.com
X-Trace: sv3-oGEaznJ0WmZ0WU74CQDIc7tWSUSBoYvtVrKMYhPBRiE4+715VbCH+RDVVNEJAs2DMiR2d+aFj+wJCA7!odNsSDggeWVOOEhMOjuXXgq/m+7uSa9VsyWrEaZdU2o0DI2oOnOca72eX4QQ8AiBHzdvU38CP5qw!GKQHgRdXTw==
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly
X-Postfilter: 1.3.40
Bytes: 3391
X-Original-Bytes: 3329
Xref: panix comp.lang.c++:1125410

On Mon, 21 Nov 2016 14:48:15 +0000
Chris Vine wrote:
> On Mon, 21 Nov 2016 13:26:07 GMT
> scott-at-slp53.sl.home (Scott Lurndal) wrote:
> > Juha Nieminen writes: =20
> > >Popping mad wrote: =20
> > >> This is an excellent explanation, but I'm still not clear on
> > >> this. I think it is saying that a static has to be declared and
> > >> defined within a compilational unit. I'm not sure why, though.
> > >> And I've asked before, and read, but I'm still not clear on what
> > >> a compilation unit is. =20
> > >
> > >A static member variable needs to exist somewhere in the executable
> > >(because, among other things, you need to be able to eg. have a
> > >pointer pointing to it). =20
> >=20
> > The confusing part for some folks is that gcc/binutils, when using
> > -O3, won't require the definition unless the address of the static
> > const value is taken. Remove -O3 and you'll start getting link
> > errors. =20
>=20
> My recollection in the case of the declaration of a const static
> integer member variable (typically with a literal value) is that you
> don't need to provide a definition for it if it is not ODR-used,
> whatever the optimization level. Taking an address is one way of
> ODR-using it. Casting it to lvalue of another type is another. I
> don't at the moment have the C++ standard in front of me to give you
> the reference.

I do now. It's =C2=A79.4.2/3. "If a non-volatile const static data member
is of integral or enumeration type, its declaration in the class
definition can specify a brace-or-equal-initializer in which every
initializer-clause that is an assignment-expression is a constant
expression (5.20). ... . The member shall still be defined in
a namespace scope if it is odr-used (3.2) in the program and the
namespace scope definition shall not contain an initializer." This
implies that the initialised const static integral member need not be
defined in namespace scope (its declaration is sufficient) if it is not
ODR-used.

Chris


--------------FFF26FD058A6765DB3A66A85
Content-Type: message/rfc822;
name="Re: hidden static.eml"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename="Re: hidden static.eml"

Path: reader2.panix.com!panix!goblin1!goblin.stu.neva.ru!border1.nntp.ams1.giganews.com!nntp.giganews.com!buffer1.nntp.ams1.giganews.com!buffer2.nntp.ams1.giganews.com!nntp.brightview.co.uk!news.brightview.co.uk.POSTED!not-for-mail
NNTP-Posting-Date: Mon, 21 Nov 2016 12:18:19 -0600
Date: Mon, 21 Nov 2016 18:18:06 +0000
From: Chris Vine
Newsgroups: comp.lang.c++
Subject: Re: hidden static
Message-ID: <20161121181806.58043cf8-at-dell.homenet>
References:




<20161121144815.63a2899c-at-dell.homenet>
<20161121173103.17c0ed02-at-dell.homenet>
X-Newsreader: Claws Mail 3.13.2 (GTK+ 2.24.31; x86_64-unknown-linux-gnu)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
X-Usenet-Provider: http://www.giganews.com
X-Trace: sv3-JEQj3mz1xKbQAxdXsTVYjiLyAGHuskHPx6rcdgJiKG1th3pQdemvzbHcbbPtRmWZPHdGZMvySdw9xkp!zJKS8AK8oubU+tgV9K6rBBOpBUduh0u5A/WvZrAjJaJGhjPcCdzUF/VwIUXFRpwZpRShEwu3uDOq!Rd2aFv50mw==
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly
X-Postfilter: 1.3.40
X-Original-Bytes: 3328
Xref: panix comp.lang.c++:1125411

On Mon, 21 Nov 2016 17:31:03 +0000
Chris Vine wrote:
> On Mon, 21 Nov 2016 14:48:15 +0000
> Chris Vine wrote:
> > On Mon, 21 Nov 2016 13:26:07 GMT
> > scott-at-slp53.sl.home (Scott Lurndal) wrote: =20
[snip]
> > > The confusing part for some folks is that gcc/binutils, when using
> > > -O3, won't require the definition unless the address of the static
> > > const value is taken. Remove -O3 and you'll start getting link
> > > errors. =20
> >=20
> > My recollection in the case of the declaration of a const static
> > integer member variable (typically with a literal value) is that you
> > don't need to provide a definition for it if it is not ODR-used,
> > whatever the optimization level. Taking an address is one way of
> > ODR-using it. Casting it to lvalue of another type is another. I
> > don't at the moment have the C++ standard in front of me to give you
> > the reference. =20
>=20
> I do now. It's =C2=A79.4.2/3. "If a non-volatile const static data memb=
er
> is of integral or enumeration type, its declaration in the class
> definition can specify a brace-or-equal-initializer in which every
> initializer-clause that is an assignment-expression is a constant
> expression (5.20). ... . The member shall still be defined in
> a namespace scope if it is odr-used (3.2) in the program and the
> namespace scope definition shall not contain an initializer." This
> implies that the initialised const static integral member need not be
> defined in namespace scope (its declaration is sufficient) if it is
> not ODR-used.

However I do now recall having experiences similar to the one you
mention. Some forms of ODR-use, such as assigning to a const
reference, may be optimized out with a sufficiently high level of
optimization, and will compile and link even though technically the
code in question is not conformant. That may be what you had in mind.
But where the static member is not ODR-used, you should be safe from
that problem.


--------------FFF26FD058A6765DB3A66A85
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
Learn mailing list
Learn-at-nylxs.com
http://lists.mrbrklyn.com/mailman/listinfo/learn

--------------FFF26FD058A6765DB3A66A85--

  1. 2016-11-01 Ruben Safir <ruben-at-mrbrklyn.com> Re: [Learn] how is it indexing in cuda
  2. 2016-11-01 Ruben Safir <ruben.safir-at-my.liu.edu> Re: [Learn] not adequately speced of explained
  3. 2016-11-01 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [Learn] how is it indexing in cuda
  4. 2016-11-01 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [Learn] not adequately speced of explained
  5. 2016-11-02 Christopher League <league-at-contrapunctus.net> Re: [Learn] Fitch Algorithm - C++
  6. 2016-11-02 Ruben Safir <mrbrklyn-at-panix.com> Re: [Learn] Fitch Algorithm - C++
  7. 2016-11-02 Ruben Safir <ruben-at-mrbrklyn.com> Re: [Learn] how is it indexing in cuda
  8. 2016-11-02 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [Learn] Fitch Algorithm - C++
  9. 2016-11-02 IEEE Computer Society <csconnection-at-computer.org> Subject: [Learn] Hear Google's John Martinis Take on Quantum Computing at
  10. 2016-11-02 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [Learn] opencl
  11. 2016-11-02 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [Learn] scheduled for tommorw
  12. 2016-11-02 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [Learn] threads tutorial
  13. 2016-11-03 Ruben Safir <mrbrklyn-at-panix.com> Re: [Learn] Fitch Algorithm - C++
  14. 2016-11-03 Ruben Safir <mrbrklyn-at-panix.com> Re: [Learn] Fitch Algorithm - C++
  15. 2016-11-03 Ruben Safir <mrbrklyn-at-panix.com> Re: [Learn] Fitch Algorithm - C++
  16. 2016-11-03 Christopher League <league-at-contrapunctus.net> Re: [Learn] huffman code
  17. 2016-11-03 Ruben Safir <ruben-at-mrbrklyn.com> Re: [Learn] huffman code
  18. 2016-11-03 Ruben Safir <ruben.safir-at-my.liu.edu> Re: [Learn] huffman code
  19. 2016-11-03 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [Learn] Fitch algorithm from the beginning
  20. 2016-11-03 From: <mrbrklyn-at-panix.com> Subject: [Learn] huffman code
  21. 2016-11-03 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [Learn] Phenology meeting
  22. 2016-11-03 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [Learn] relevant hackathon
  23. 2016-11-03 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [Learn] relevant hackathon
  24. 2016-11-04 Ruben Safir <mrbrklyn-at-panix.com> Re: [Learn] huffman code
  25. 2016-11-04 Christopher League <league-at-contrapunctus.net> Subject: [Learn] Fitch/Sankoff
  26. 2016-11-05 Christopher League <league-at-contrapunctus.net> Re: [Learn] Fwd: templates within templates
  27. 2016-11-05 ruben safir <ruben-at-mrbrklyn.com> Subject: [Learn] Fwd: Re: const T vs T const
  28. 2016-11-05 ruben safir <ruben-at-mrbrklyn.com> Subject: [Learn] Fwd: Template Library files and Header linking troubles
  29. 2016-11-05 ruben safir <ruben-at-mrbrklyn.com> Subject: [Learn] Fwd: templates within templates
  30. 2016-11-06 Ruben Safir <mrbrklyn-at-panix.com> Re: [Learn] Fwd: templates within templates
  31. 2016-11-06 Ruben Safir <ruben-at-mrbrklyn.com> Re: [Learn] Fwd: templates within templates
  32. 2016-11-06 Ruben Safir <mrbrklyn-at-panix.com> Re: [Learn] Fwd: templates within templates
  33. 2016-11-06 Christopher League <league-at-contrapunctus.net> Re: [Learn] Fwd: templates within templates
  34. 2016-11-06 Ruben Safir <mrbrklyn-at-panix.com> Re: [Learn] Fwd: templates within templates
  35. 2016-11-06 Ruben Safir <ruben-at-mrbrklyn.com> Re: [Learn] Fwd: templates within templates
  36. 2016-11-06 Ruben Safir <ruben-at-mrbrklyn.com> Re: [Learn] Fwd: templates within templates
  37. 2016-11-06 Ruben Safir <ruben-at-mrbrklyn.com> Re: [Learn] GNU Parallel 20161022 ('Matthew') released [stable]
  38. 2016-11-07 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [Learn] templates and ostream for future reference
  39. 2016-11-08 Christopher League <league-at-contrapunctus.net> Re: [Learn] C++ signature ambiguity
  40. 2016-11-08 Ruben Safir <ruben.safir-at-my.liu.edu> Re: [Learn] C++ signature ambiguity
  41. 2016-11-08 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [Learn] C++ signature ambiguity
  42. 2016-11-08 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [Learn] Fwd: Invitation: Phylogeny meeting -at- Weekly from 10:15 to
  43. 2016-11-08 Ruben Safir <mrbrklyn-at-panix.com> Subject: [Learn] Fwd: [nylug-talk] RSVP open: Wed Nov 16,
  44. 2016-11-09 Christopher League <league-at-contrapunctus.net> Re: [Learn] merge sort parallel hw
  45. 2016-11-09 Ruben Safir <ruben-at-mrbrklyn.com> Re: [Learn] merge sort parallel hw
  46. 2016-11-09 Ruben Safir <ruben-at-mrbrklyn.com> Re: [Learn] merge sort parallel hw
  47. 2016-11-09 Christopher League <league-at-contrapunctus.net> Re: [Learn] merge sort parallel hw
  48. 2016-11-09 Ruben Safir <ruben-at-mrbrklyn.com> Re: [Learn] mergesort tutorial
  49. 2016-11-09 Christopher League <league-at-contrapunctus.net> Re: [Learn] mergesort tutorial
  50. 2016-11-09 Christopher League <league-at-contrapunctus.net> Re: [Learn] namespace and external files confusion
  51. 2016-11-09 Ruben Safir <ruben-at-mrbrklyn.com> Re: [Learn] namespace and external files confusion
  52. 2016-11-09 From: "Carlos R. Mafra" <crmafra-at-gmail.com> Re: [Learn] Question about a small change
  53. 2016-11-09 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [Learn] =?utf-8?q?C++_call_of_overloaded_=E2=80=98track=28int*=26?=
  54. 2016-11-09 ruben safir <ruben-at-mrbrklyn.com> Subject: [Learn] Fwd: lost arguments
  55. 2016-11-09 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [Learn] Fwd: [dinosaur] Dating origins of dinosaurs,
  56. 2016-11-09 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [Learn] merge sort parallel hw
  57. 2016-11-09 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [Learn] mergesort tutorial
  58. 2016-11-09 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [Learn] namespace and external files confusion
  59. 2016-11-10 Christopher League <league-at-contrapunctus.net> Re: [Learn] merge sort parallel hw
  60. 2016-11-10 Ruben Safir <mrbrklyn-at-panix.com> Re: [Learn] merge sort parallel hw
  61. 2016-11-10 Ruben Safir <mrbrklyn-at-panix.com> Re: [Learn] merge sort parallel hw
  62. 2016-11-10 Ruben Safir <ruben.safir-at-my.liu.edu> Re: [Learn] merge sort parallel hw
  63. 2016-11-10 Ruben Safir <ruben-at-mrbrklyn.com> Re: [Learn] [Hangout-NYLXS] mergesort tutorial
  64. 2016-11-10 Ruben Safir <mrbrklyn-at-panix.com> Subject: [Learn] Fwd: [Hangout-NYLXS] ease your mind- everything in the
  65. 2016-11-10 Ruben Safir <ruben.safir-at-my.liu.edu> Subject: [Learn] Fwd: [Hangout-NYLXS] R Programming Workshop
  66. 2016-11-10 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [Learn] Paleocast phenogenetic tree building
  67. 2016-11-11 Christopher League <league-at-contrapunctus.net> Re: [Learn] merge sort parallel hw
  68. 2016-11-12 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [Learn] HW of mergesort in parallel
  69. 2016-11-13 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [Learn] merge sort in parallel assignment
  70. 2016-11-14 Christopher League <league-at-contrapunctus.net> Re: [Learn] merge sort in parallel assignment
  71. 2016-11-14 Ruben Safir <ruben-at-mrbrklyn.com> Re: [Learn] merge sort in parallel assignment
  72. 2016-11-14 Ruben Safir <ruben-at-mrbrklyn.com> Re: [Learn] merge sort parallel hw
  73. 2016-11-14 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [Learn] CUDA and video
  74. 2016-11-14 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [Learn] PNG Graphic formats and CRCs
  75. 2016-11-15 ruben safir <ruben-at-mrbrklyn.com> Subject: [Learn] Fwd: PNG coding
  76. 2016-11-15 ruben safir <ruben.safir-at-my.liu.edu> Subject: [Learn] Fwd: PNG Coding
  77. 2016-11-16 Ruben Safir <ruben-at-mrbrklyn.com> Re: [Learn] Fwd: lost arguments
  78. 2016-11-16 Ruben Safir <ruben-at-mrbrklyn.com> Re: [Learn] relevant hackathon
  79. 2016-11-16 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [Learn] C++ Workshop Announcement
  80. 2016-11-16 Ruben Safir <mrbrklyn-at-panix.com> Subject: [Learn] Fwd: Re: ref use
  81. 2016-11-16 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [Learn] ref use
  82. 2016-11-16 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [Learn] why use a reference wrapper int his example
  83. 2016-11-17 Ruben Safir <mrbrklyn-at-panix.com> Re: [Learn] [Hangout-NYLXS] at K&R now
  84. 2016-11-17 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [Learn] Fwd: [Hangout-NYLXS] Fwd: PNG Coding
  85. 2016-11-18 ruben safir <ruben-at-mrbrklyn.com> Subject: [Learn] C++ workshop and usenet responses
  86. 2016-11-19 ruben safir <ruben-at-mrbrklyn.com> Subject: [Learn] Fwd: ref use
  87. 2016-11-20 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [Learn] when is the constructor called for an object
  88. 2016-11-21 ruben safir <ruben-at-mrbrklyn.com> Subject: [Learn] Fwd: creating a binary tree
  89. 2016-11-21 ruben safir <ruben-at-mrbrklyn.com> Subject: [Learn] Fwd: hidden static
  90. 2016-11-21 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [Learn] Fwd: ISBI 2017 Call for Abstracts and Non-Author
  91. 2016-11-21 ruben safir <ruben-at-mrbrklyn.com> Subject: [Learn] Fwd: PNG coding
  92. 2016-11-21 ruben safir <ruben-at-mrbrklyn.com> Subject: [Learn] Fwd: Re: the new {} syntax
  93. 2016-11-21 ruben safir <ruben-at-mrbrklyn.com> Subject: [Learn] Fwd: when is the constructor called for an object
  94. 2016-11-21 ruben safir <ruben-at-mrbrklyn.com> Subject: [Learn] Fwd: when is the constructor called for an object
  95. 2016-11-21 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [Learn] Fwd: [dinosaur] Eoconfuciusornis feather keratin and
  96. 2016-11-21 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [Learn] look what I found
  97. 2016-11-22 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [Learn] Cuccuency book
  98. 2016-11-22 ruben safir <ruben.safir-at-my.liu.edu> Subject: [Learn] declare a func or call an object
  99. 2016-11-22 Ruben Safir <ruben.safir-at-my.liu.edu> Subject: [Learn] Fwd: Re: Using CLIPS as a library
  100. 2016-11-23 Ruben Safir <ruben.safir-at-my.liu.edu> Subject: [Learn] Fwd: Simple C++11 Wrapper for CLIPS 6.30
  101. 2016-11-23 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [Learn] Parrelel Programming HW2 with maxpath
  102. 2016-11-24 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [Learn] great research news for big data
  103. 2016-11-24 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [Learn] mapping algorithms
  104. 2016-11-24 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [Learn] Todays meeting
  105. 2016-11-25 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [Learn] Fwd: [dinosaur] Flightless theropod phylogenetic variation
  106. 2016-11-26 Ruben Safir <ruben-at-mrbrklyn.com> Re: [Learn] Note to self for Thursday
  107. 2016-11-26 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [Learn] Fitch etc
  108. 2016-11-26 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [Learn] Note to self for Thursday
  109. 2016-11-26 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [Learn] operator<<() overloading details and friend
  110. 2016-11-27 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [Learn] 130 year old feathers analysis
  111. 2016-11-27 ruben safir <ruben-at-mrbrklyn.com> Subject: [Learn] Fwd: ACM/SPEC ICPE 2017 - Call for Tutorial Proposals
  112. 2016-11-27 ruben safir <ruben-at-mrbrklyn.com> Subject: [Learn] Fwd: ACM/SPEC ICPE 2017 - Call for Workshop Proposals
  113. 2016-11-27 ruben safir <ruben-at-mrbrklyn.com> Subject: [Learn] Fwd: CfP 22nd Conf. Reliable Software Technologies,
  114. 2016-11-27 ruben safir <ruben-at-mrbrklyn.com> Subject: [Learn] Fwd: Seeking contributors for psyche-c
  115. 2016-11-29 Christopher League <league-at-contrapunctus.net> Re: [Learn] Look at this exciting output by my test program
  116. 2016-11-29 Ruben Safir <ruben-at-mrbrklyn.com> Re: [Learn] Look at this exciting output by my test program
  117. 2016-11-29 Ruben Safir <ruben-at-mrbrklyn.com> Re: [Learn] Look at this exciting output by my test program
  118. 2016-11-29 Christopher League <league-at-contrapunctus.net> Re: [Learn] Quantum Entanglement
  119. 2016-11-29 Ruben Safir <mrbrklyn-at-panix.com> Re: [Learn] Quantum Entanglement
  120. 2016-11-29 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [Learn] Here is the paper I was talking out
  121. 2016-11-29 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [Learn] Look at this exciting output by my test program
  122. 2016-11-29 nylxs <mrbrklyn-at-optonline.net> Subject: [Learn] Look at this exciting output by my test program
  123. 2016-11-29 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [Learn] Quantum Entanglement
  124. 2016-11-29 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [Learn] The Death of PBS
  125. 2016-11-29 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [Learn] witmer lab ohio and 3d imaging
  126. 2016-11-30 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [Learn] phylogenetic crawler

NYLXS are Do'ers and the first step of Doing is Joining! Join NYLXS and make a difference in your community today!