Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

What does the 'static' in "vector<static FixPt> Data1024;" stand for?

0 views
Skip to first unread message

Cuthbert

unread,
Dec 29, 2008, 9:06:27 PM12/29/08
to
Hi folks,

I am a newcomer to C++ and am reading a example code right now. In
this example code, the author used a lot of "vector<static DataType>
somename;". I know the static vector definition but wonder what's the
different between static vector and "vector<static xxx> xxx"? Can
anybody explain this for me? Thanks a lot.


Cuthbert

alfps

unread,
Dec 29, 2008, 10:36:09 PM12/29/08
to

The usage

vector<static T> v;

is not valid standard C++.

If you're sure that the example was /exactly/ like that, then please
tell the group what book you're reading, and locate the nearest
fireplace.

There remains of course the possibility of some compiler-specific
language extension, and/or that you remember the example incorrectly.

Cheers & hth.,

- Alf

Cuthbert

unread,
Dec 30, 2008, 3:19:01 AM12/30/08
to
Alf, thanks for your reply.

I tried to take off 'static' idenfier and compiled the source code. It
passed in VC2005pro and worked just like original code with 'static'.
Is it typo or something else? don't know.

Cuthbert

Christian Hackl

unread,
Dec 30, 2008, 5:59:48 AM12/30/08
to
Cuthbert ha scritto:

> I tried to take off 'static' idenfier and compiled the source code. It
> passed in VC2005pro and worked just like original code with 'static'.
> Is it typo or something else? don't know.

It's not standard C++, anyway. If you try to compile the code with gcc
or Comeau, you'll see that it will fail. Strange enough, it compiles
fine with VC even if you disable language extensions. Maybe it's a
compiler bug. You should ask in a newsgroup where VC-specific issues are
on-topic, e.g. microsoft.public.vc.language.


--
Christian Hackl
ha...@sbox.tugraz.at

Jeff Schwab

unread,
Dec 30, 2008, 8:27:53 AM12/30/08
to

And check the book's web site for errata, or email the publisher.

Noah Roberts

unread,
Dec 30, 2008, 11:31:15 AM12/30/08
to

Another thing to remember is that a lot of schools use really old books
to teach C++, if they teach it at all. It could be some pre-standard
monstrosity.

Juha Nieminen

unread,
Dec 30, 2008, 1:45:27 PM12/30/08
to
Christian Hackl wrote:
> Strange enough, it compiles
> fine with VC even if you disable language extensions.

What is std::vector<static something> supposed to do in VC?

jason.c...@gmail.com

unread,
Dec 30, 2008, 2:17:57 PM12/30/08
to

I don't *think* it does anything, as this program compiles and runs
with no issues:

== BEGIN CODE ==

#include <cassert>
#include <vector>
#include <typeinfo>
using namespace std;

class A { };

int main () {

A a;
vector<A> as(1);
vector<static A> sas(1);

assert(typeid(as) == typeid(sas));
assert(typeid(as[0]) == typeid(sas[0]));

as.push_back(a);
sas.push_back(a);
}

== END CODE ==

It seems to be ignored. Also, FWIW, typeid(sas).name() and typeid(sas
[0]).name() return:

sas = class std::vector<class A,class std::allocator<class A> >
sas[0] = class A

I wonder what book he's reading.

Jason

jason.c...@gmail.com

unread,
Dec 30, 2008, 2:31:26 PM12/30/08
to
On Dec 30, 2:17 pm, "jason.cipri...@gmail.com"

Also it does not affect the storage duration of vector elements or
anything like that (was wondering if maybe a VC bug was about to be
revealed). The following program fills 3 vectors with [1 2 3], [4 5
6], and [7 8 9] respectively, and prints them to verify that that is
indeed their contents:


== BEGIN CODE ==

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

int next () {
static int n;
return ++n;
}

ostream & operator << (ostream &s, const vector<int> &v) {
copy(v.begin(), v.end(), ostream_iterator<int>(s, " "));
return s << endl;
}

int main () {

vector<int> a(3);
vector<static int> b(3);
vector<static int> c(3);

generate(a.begin(), a.end(), next);
generate(b.begin(), b.end(), next);
generate(c.begin(), c.end(), next);

cout << a << b << c;

}

== END CODE ==


The expected output is produced:

1 2 3
4 5 6
7 8 9

This is VC 2008. I suppose it's a bug that it accepts invalid code.

Jason

0 new messages