Monday, November 2, 2009

comp.lang.c++ - 26 new messages in 17 topics - digest

comp.lang.c++
http://groups.google.com/group/comp.lang.c++?hl=en

comp.lang.c++@googlegroups.com

Today's topics:

* ☎ Y(^o^)Y☎HOT sale Brand Sweaters Boss,Gucci,Lacoste,Armani,Prada,Polo,DG,
Paul-Smith,Versace,Juicy,Edhardy,etc sweaters - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c++/t/01904e49a7949195?hl=en
* const char pointers - 4 messages, 4 authors
http://groups.google.com/group/comp.lang.c++/t/1ce65352cda0da4a?hl=en
* ☎☎☎surprise: wholesale low price and high quality, hot brand goods free
shipping coat at www.ecyaya.com - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c++/t/9e1ccf26d238e2a6?hl=en
* Ambiguous in MI - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c++/t/0c8356a20fbb2259?hl=en
* Why extracting string from stringstream(a) fails? - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c++/t/515946bf9554ad00?hl=en
* Should the 'this' pointer be explicitly used as a rule? - 2 messages, 1
author
http://groups.google.com/group/comp.lang.c++/t/dc65e966f7b73ba3?hl=en
* c++ build question - 2 messages, 2 authors
http://groups.google.com/group/comp.lang.c++/t/92a3f21ecdea9375?hl=en
* Binary file IO: Converting imported sequences of chars to desired type - 1
messages, 1 author
http://groups.google.com/group/comp.lang.c++/t/690c45c0197f60ef?hl=en
* Portable library to measure time - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c++/t/9215c47c4398d6d8?hl=en
* efficient swap method - 3 messages, 2 authors
http://groups.google.com/group/comp.lang.c++/t/d9911a558abbff19?hl=en
* token concatenation macro - 2 messages, 2 authors
http://groups.google.com/group/comp.lang.c++/t/156c49cafbfac12a?hl=en
* difference between decorator and composite? - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c++/t/dbbbdcb21a44ae08?hl=en
* DBL_MAX - 2 messages, 2 authors
http://groups.google.com/group/comp.lang.c++/t/f74230c5e235b227?hl=en
* days and date types - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c++/t/e8bb8723ba7eafa3?hl=en
* mutual dependency - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c++/t/c7c749b253887b89?hl=en
* Y(^o^)Y free shipping wholesale low price shoes and Jeans etc (www.ecyaya.
com) - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c++/t/0c6e37fc34de932c?hl=en
* Pointers - *p++ - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c++/t/f8e5dfe803653b78?hl=en

==============================================================================
TOPIC: ☎ Y(^o^)Y☎HOT sale Brand Sweaters Boss,Gucci,Lacoste,Armani,Prada,Polo,
DG,Paul-Smith,Versace,Juicy,Edhardy,etc sweaters
http://groups.google.com/group/comp.lang.c++/t/01904e49a7949195?hl=en
==============================================================================

== 1 of 1 ==
Date: Sun, Nov 1 2009 11:26 pm
From: peng Selina


☎ Y(^o^)Y☎HOT sale Brand Sweaters
Boss,Gucci,Lacoste,Armani,Prada,Polo,DG,Paul-
Smith,Versace,Juicy,Edhardy,etc sweaters
Sweater {www.toptradea.com}
Armani-Sweater {www.toptradea.com}

Boss-Sweater {www.toptradea.com}

D&G-Sweater {www.toptradea.com}

Edhardy-Sweater {www.toptradea.com}

Gucci-Sweater {www.toptradea.com}

Juicy-Sweater {www.toptradea.com}

Lacoste-Sweater {www.toptradea.com}

Paul-Smith-Sweater {www.toptradea.com}

Polo-Sweater {www.toptradea.com}

Prada-Sweater {www.toptradea.com}

Versace-Sweater {www.toptradea.com}

==============================================================================
TOPIC: const char pointers
http://groups.google.com/group/comp.lang.c++/t/1ce65352cda0da4a?hl=en
==============================================================================

== 1 of 4 ==
Date: Mon, Nov 2 2009 12:18 am
From: crystal twix


For an assignment, I am trying to write a string function that returns
a portion of the string. My parameter list is a const char word[],
int start, int end, char result[].

Being new to arrays and pointers, I'm not sure what is the way I want
to handle the const char word[] without getting compiler warnings of
"Assignment qualifier discards qualifiers from pointer target type. I
thought I could create a pointer named temp

int *temp = word;

and get the string by using the start and end parameters by
incrementing the pointer through the array and returning result. But
I'm kind of stuck on where to start. Thanks.


== 2 of 4 ==
Date: Mon, Nov 2 2009 3:09 am
From: "Daniel T."


crystal twix <jonwongfanclub@gmail.com> wrote:

> For an assignment, I am trying to write a string function that returns
> a portion of the string. My parameter list is a const char word[],
> int start, int end, char result[].
>
> Being new to arrays and pointers, I'm not sure what is the way I want
> to handle the const char word[] without getting compiler warnings of
> "Assignment qualifier discards qualifiers from pointer target type. I
> thought I could create a pointer named temp
>
> int *temp = word;
>
> and get the string by using the start and end parameters by
> incrementing the pointer through the array and returning result. But
> I'm kind of stuck on where to start. Thanks.

So something like:

void myFunc(const char word[], int start, int end, char result[]);

I suggest you start simple:

int main() {
char result[32] = 0;
myFunc("", 0, 0, result);
assert(strcmp(result, "") == 0);

// once you get the above working then:
myFunc("hello", 0, 1, result);
assert(strcmp(result, "h") == 0);
myFunc("world", 0, 1, result);
assert(strcmp(result, "w") == 0);

// then make sure your edge conditions work
myFunc("hello", 4, 5, result);
assert(strcmp(result, "o") == 0);
myFunc("world", 4, 5, result);
assert(strcmp(result, "d") == 0);
}

Get all the above working, if you run into trouble, then post what you
have so far here and I'll help you out.


== 3 of 4 ==
Date: Mon, Nov 2 2009 3:48 am
From: Sam


crystal twix writes:

> For an assignment, I am trying to write a string function that returns
> a portion of the string. My parameter list is a const char word[],
> int start, int end, char result[].
>
> Being new to arrays and pointers, I'm not sure what is the way I want
> to handle the const char word[] without getting compiler warnings of
> "Assignment qualifier discards qualifiers from pointer target type. I
> thought I could create a pointer named temp

You will need to use separate pointers that access "word", and ones that
access "result" (if any).

Declare the pointers that access "word" as "const char *", instead of "char
*". If you need a pointer to do whatever you need with "result", that's
still a plain "char *".


== 4 of 4 ==
Date: Mon, Nov 2 2009 4:12 am
From: paperab


On Nov 2, 8:18 am, crystal twix <jonwongfanc...@gmail.com> wrote:
> For an assignment, I am trying to write a string function that returns
> a portion of the string.  My parameter list is a const char word[],
> int start, int end, char result[].
>
> int *temp = word;

"word" is a "const char pointer" so you should assign it to something
like:

const char* temp = word;

But this has not solved your problem (only creates another pointer to
your original character sequence).

If you function has to write a portion of your sequence (it's not a
std string but a zero terminated string I suppose), you have to place
a 0x00 at the end of the new sequence (you are not allowed to modify
the original sequence I suppose again).

Solve it without using any std routine means you need a simple loop:

void subSequence(const char word[], const int start, const int end,
char result[]) {
int k = 0;
for(int i=start; i<=end; i++) {
result[k++]=word[i];
}
result[k]=0x00;
}

and you can call it with:

char result[11] = {0x00};
subSequence("ciaociaoFIVE5hello", 8, 12, result);

then in result you must have: "FIVE5"...

Cheers


==============================================================================
TOPIC: ☎☎☎surprise: wholesale low price and high quality, hot brand goods free
shipping coat at www.ecyaya.com
http://groups.google.com/group/comp.lang.c++/t/9e1ccf26d238e2a6?hl=en
==============================================================================

== 1 of 1 ==
Date: Mon, Nov 2 2009 12:19 am
From: ecyaya


☎☎☎surprise: wholesale low price and high quality, hot brand goods
free shipping coat at www.ecyaya.com

ecyaya.com (www.ecyaya.com) wholesale nike jordan
sneakers big cheap air jordan sneakers for sale.discount china nike
dunk sb shoes,nike exclusive jordan sneakers,custom nike air force
one
sneakers,nike dunk cheap,nike jordan sneakers wholesale,discount
supra www.ecyaya.com
shoes wholesale new balance shoes puma shoes,cheap adidas
shoes,authentic jordan sneakers,wholesale nike max 90 sheos,china
supplier nike max 87 max 2009 max 360 shoes,hot max 95 shoes,free
shipping prada shoes,nike retro jordan snekaers,other nike running
shoes,wholesale nike lebron james 6 sneakers,cheap nike zoom kobe 4
sneakers free shipping, kids jordan sneakers wholesale, nike air
force www.ecyaya.com
one 1 fusion jordan sneakers,buy sneaker for cheap,nike air max
premium leather sneakers,gucci tennis shoes for discount,high quality
gucci shoes,wholesale jordan fusion sneakers from china supply,cheap
air bape sneakers, China Nike product manufacturer,gucci shoes,supply
puma sneakers timberland shoes,discounts Jordans kicks shoes Cheap
Discount Basketball Sneakers on Sale, Nike Retro Air Jordan Melo M5,
United States Christian Audigier T-Shirt Wholesale Christian Audigier
T-Shirt New cheap Christian Audigier T-Shirt Manufacturers www.ecyaya.com
Suppliers,Wholesale Ed hardy AF T-Shirt, Discounted Louis Vuitton
Designer Handbags Clothes,Chanel and Coach Designer Handbag Wallets
Purse,Replica Louis Vuitton Handbag Accessories,Cheap Gucci handbags
Designer handbags by Gucci leather Purses Belt sunglasses,nike air
zoom signature basketball shoes, etc. www.ecyaya.com


www.ecyaya.com will bring you surprise. www.ecyaya.com
Here you can find your favorite. www.ecyaya.com
Just do it as soon as possible!!! www.ecyaya.com


welcome to visit!


Web address:www.ecyaya.com

==============================================================================
TOPIC: Ambiguous in MI
http://groups.google.com/group/comp.lang.c++/t/0c8356a20fbb2259?hl=en
==============================================================================

== 1 of 1 ==
Date: Mon, Nov 2 2009 1:33 am
From: James Kanze


On Oct 31, 5:36 pm, Pavel
<pauldontspamt...@removeyourself.dontspam.yahoo> wrote:
> James Kanze wrote:

[...]
> > I suspect (but I'm really just guessing) that what he's
> > expecting is the behavior of Java: that C::fun() will
> > provide the implementation of B::fun(), just because the
> > function happens to accidentally have the same name in two
> > different, unrelated classes. C++ doesn't have this defect
> > in the language; you have to explicitly tell the compiler
> > that the implementation in C::fun() is the one you want
> > here, by defining an A::fun() which calls C::fun().

> You are confusing me.. Care to share an example of Java code
> you had in mind?

It's been a while since I've last programmed in Java, but if I
recall correctly, something like the following is perfectly good
Java:

interface I
{
void f();
}

class B
{
public void f() {}
}

class D extends B implements I
{
}

The B::f() overides the I::f(), even though the author of B has
no idea what I is or expects. Given the equivalent in C++:

class I
{
public:
virtual ~I() {}
virtual void f() = 0;
};

class B
{
public:
void f() {}
};

class D : public B, public I
{
};

, class D is still abstract, since the function B::f() does not
override I::f(). The author of D must make it explicit by
defining D::f().

--
James Kanze

==============================================================================
TOPIC: Why extracting string from stringstream(a) fails?
http://groups.google.com/group/comp.lang.c++/t/515946bf9554ad00?hl=en
==============================================================================

== 1 of 1 ==
Date: Mon, Nov 2 2009 1:49 am
From: James Kanze


On Oct 31, 6:45 pm, Pavel
<pauldontspamt...@removeyourself.dontspam.yahoo> wrote:
> James Kanze wrote:

[...]
> > I've still got to examine the new text. The reason for the rule
> > (I think) is for things like:

> > struct S { A a; B b; }; // A and B class types...
> > S f();

> > B const& rb = f().b;

> > What should be the lifetime of the S returned by f(). I'd
> > argue that the current text of the standard says that its
> > lifetime must end at the end of the full expression. But
> > the only way to end it, while extending the lifetime of the
> > B temporary bound to rb, is to copy it out of the S object.

> Why does the lifetime of B temporary has to be extended?

Because the standard says so. When a reference is initialized
with a temporary, the lifetime of that temporary is extended to
match that of the reference. (See §12.2.)

> Do you imply this because the lifetime of rb extends beyond
> the one of S temporary?

Yes. The standard clearly requires that the lifetime of the
temporary bound to the reference be extended to that of the
reference. It also clearly requires that the lifetime of the
temporary S terminate at the end of the full expression. The
current standard allows a copy here, and the compilers I've
checked in the past (and the one I have access to at present:
VC++) do make a copy. The current draft forbids the copy here,
while not changing any of the other requirements; I'm not sure
how they expect this to be implemented.

--
James Kanze

==============================================================================
TOPIC: Should the 'this' pointer be explicitly used as a rule?
http://groups.google.com/group/comp.lang.c++/t/dc65e966f7b73ba3?hl=en
==============================================================================

== 1 of 2 ==
Date: Mon, Nov 2 2009 1:57 am
From: James Kanze


On Oct 31, 7:54 pm, Pavel
<pauldontspamt...@removeyourself.dontspam.yahoo> wrote:
> James Kanze wrote:
> > Of course, with really good naming, you don't need anything;
> > the name contains enough semantic information so that it's
> > obvious whether it is a member (from the semantics). In
> > practice, I've found that most people (including myself)
> > don't name that well, and that the my_ prefix (or our_ for
> > static members) is helpful in many cases, enough to be worth
> > standardizing on. (But I admit exceptions: public data
> > members, for example, don't normally get it.)

[...]
> > The best would have been if there were some way
> > of enforcing good enough names so that the distinction
> > wouldn't be necessary. In practice, I find too that the
> > real motivation for the prefix/suffix is laziness: I'm too
> > lazy to create significantly different names for parameters
> > and members in the setters. (The real convention should
> > probably be to "prefix" both: my_state or my_current_state
> > for the member, and new_state for the parameter, or
> > initial_state if it is a parameter of a constructor. But as
> > I said, I'm too lazy to do this consistently.)

> BTW, there used to be a convention to use an 'a' article for
> parameters: void draw(Shape aShape){...}. That was not too bad
> except that sometimes it read ugly for native English speakers
> (e.g. string join(const vector<string> &aParts) or
> copy(Iterator aBegin, Iterator anEnd, Iterator aDestination)).

I've seen that one, too. For plurials, they used some, e.g.:
someParts (instead of aParts).

> Some drawbacks of encoding scope and accessibility into "good
> names" (I assume you mean the names encoded as self-explaining
> short phrases):

> 1. Laziness is the fact of life (and the driving engine of the
> progress at that); if even you with your rigor admit being
> lazy, how can you reasonably expect from others not to?

Realistically, I don't expect it, but the projects I've worked
on where the programmers have come closest to the ideal are also
those which ended up the most robust (and were the least
expensive to develop in the long run).

> 2. The accessibility and scope of a name are "always there"
> whereas semantics changes and may on an occasion clash with
> whatever "wordy" naming convention you choose.

This is a serious problem. If the semantics of a parameter
changes, you have to examine every call site, to be sure that
the arguments passed correspond to the new semantics.
Realistically, this means that you must change the name of the
function, or possibly the types in a way that won't compile, so
that you get a compiler error. If you're providing lower level
functions for other users, you may even have to continue to
provide the old function, with the old semantics, along side the
new one.

--
James Kanze


== 2 of 2 ==
Date: Mon, Nov 2 2009 1:59 am
From: James Kanze


On Oct 31, 7:12 pm, Pavel
<pauldontspamt...@removeyourself.dontspam.yahoo> wrote:
> Juha Nieminen wrote:
> > Paavo Helde wrote:
> >> Are you talking about data members or member functions?
> >> Non-member functions are typically qualified by the
> >> namespace, e.g. std::sort(), so I see no urgent need for
> >> distinguishing member functions.

> > Except for functions in a nameless namespace.

> >> For data members, I have grown a habit to use trailing
> >> underscore for all data member names, to distinguish them
> >> from local variables and parameters. Less typing than
> >> this-> and cannot be forgotten accidentally.

> > I don't know who first invented that convention, but it
> > seems quite popular, and I really can't understand why. IMO
> > an underscore truly makes code look more obfuscated than
> > other possible choices. Often you have to follow that
> > underscore with a dot or a ->, which makes it confusing.

> I sometimes think I may be the one to blame ;-). Somewhere
> around 1993,

The convention is older than that. I know I heard about it
about then, as an already established convention. And I know of
code using it as early as 1995.

--
James Kanze

==============================================================================
TOPIC: c++ build question
http://groups.google.com/group/comp.lang.c++/t/92a3f21ecdea9375?hl=en
==============================================================================

== 1 of 2 ==
Date: Mon, Nov 2 2009 2:08 am
From: James Kanze


On Nov 1, 11:02 am, Angus <anguscom...@gmail.com> wrote:

> I hope this is an ok topic for this forum.

> When I compile a C++ file I can specify on the command line a
> macro.

Formally, the C++ standard doesn't say anything about this:-).
But in practice, yes; every compiler has some means of
"predefining" preprocessor variables (and every compiler also
has a few that are automatically predefined as well). For that
matter, every compiler I've seen uses the D option (typically
-D, but /D is generally accepted under Windows as well), with
some variation as to whether there can be a space between the D
and the preprocessor symbol. (In other words, "-D_DEBUG" can be
used more or less portably. But since most of the rest of the
command line is totally unportable, it really doesn't matter.)

> In my compiler it can be eg /D "_DEBUG". But on my command
> line I can also specify /Od - which disables optimisations.
> Are they the same thing?

No. The "/O" part and the "/D" part are the same thing:
compiler options (or directives). The first directs the
compiler to pre-define the following symbol; the second directs
it configure optimization according to the following flags.

> I can also use #define _DEBUG in my source file. Does that
> have the same effect as the command line /D "DEBUG"?

As /D _DEBUG? More or less, provided the #define _DEBUG is the
first line of your program (e.g. before any includes).

Note that _DEBUG is a special symbol, whose effects are defined
by the standard, and that it is not designed to be defined in
the command line or at the top of the code, but rather somewhere
within the code, before including <assert.h> (for a second
time), so that you only turn off assertions around the critical
block, and not everywhere.

--
James Kanze


== 2 of 2 ==
Date: Mon, Nov 2 2009 4:04 am
From: Pete Becker


James Kanze wrote:
>
> Note that _DEBUG is a special symbol, whose effects are defined
> by the standard, and that it is not designed to be defined in
> the command line or at the top of the code, but rather somewhere
> within the code, before including <assert.h> (for a second
> time), so that you only turn off assertions around the critical
> block, and not everywhere.
>

Umm, that's NDEBUG. _DEBUG is often used to indicate a debug build, but
that's a convention, not a requirement.

--
Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of
"The Standard C++ Library Extensions: a Tutorial and Reference"
(www.petebecker.com/tr1book)

==============================================================================
TOPIC: Binary file IO: Converting imported sequences of chars to desired type
http://groups.google.com/group/comp.lang.c++/t/690c45c0197f60ef?hl=en
==============================================================================

== 1 of 1 ==
Date: Mon, Nov 2 2009 2:12 am
From: James Kanze


On Oct 31, 2:19 pm, Rune Allnor <all...@tele.ntnu.no> wrote:
> On 30 Okt, 17:08, James Kanze <james.ka...@gmail.com> wrote:

> > On Oct 30, 9:37 am, Rune Allnor <all...@tele.ntnu.no> wrote:

> > > On 30 Okt, 09:44, James Kanze <james.ka...@gmail.com> wrote:
> > [...]
> > > So what does text-based formats actually buy you?

> > Shorter development times, less expensive development, greater
> > reliability...

> > In sum, lower cost.

> As long as you keep two factors in mind:

> 1) The user's time is not yours (the programmer) to waste.
> 2) The users's storage facilities (disk space, network
> bandwidth etc) are not yours (the programmer) to waste.

The user pays for your time. Spending it to do something which
results in a less reliable program, and that he doesn't need, is
irresponsible, and borders on fraud.

> Those who want easy, not awfully challenging jobs might be
> better off flipping burgers.

Writing the most reliable programs for the lowest cost is
challenging enough without going out of your way to make it
harder. If you're an amateur, doing this for fun, do whatever
amuses you the most. If you're a professional, selling your
services, professional ontology requires provided the best
service possible at the lowest price possible.

--
James Kanze

==============================================================================
TOPIC: Portable library to measure time
http://groups.google.com/group/comp.lang.c++/t/9215c47c4398d6d8?hl=en
==============================================================================

== 1 of 1 ==
Date: Mon, Nov 2 2009 2:18 am
From: James Kanze


On Nov 1, 3:45 pm, "BGB / cr88192" <cr88...@hotmail.com> wrote:
> "Julek" <julek...@go2.pl> wrote in message

> news:90319dc1-1978-46f1-81f5-37937305da3e@z41g2000yqz.googlegroups.com...

> > Is there any simple library that can return a systemtime in
> > a resolution of max. 10ms, working on both Windows XP and
> > modern Linux? time() works on both but has a resolution of
> > 1s. There is GetSystsmTime on Windows with 10ms resolution,
> > there are probably also some functions for Linux - but maybe
> > there is some library works on both these OSes?

> don't use a library for what you can trivially do yourself...

That's ridiculous. You're job is to provide the best possible
solution at the lowest possible cost. Reinventing something
that is already available should only be done when there is a
very good reason for not using what is available. (Copyright
restrictions come to mind---some projects can't use GPL, for
example.)

> using libs in this case does little more than create external
> dependencies for which any potential users of said code may be
> forced to deal with later.

If you're using a third party library, users never see it.

> a lib is good if it is known to be commonly or near
> universally available, is already in use of a project, or
> represents a non-trivial amount of work, but otherwise I feel
> use of libs is ill-advised, as it may create portability
> issues (and people trying to dig around online to find "X
> obscure library no one has heard of", or figuring out how to
> do likewise by looking at the code and figuring out what the
> API calls do...)..

> now, maybe of some help:
> #ifdef linux
> ...
> gettimeofday(...);
> ...
>

No comments: