Sunday, December 28, 2008

comp.lang.c++ - 25 new messages in 13 topics - digest

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

comp.lang.c++@googlegroups.com

Today's topics:

* luxury Products - www.cicigogo.cn - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c++/t/0a678e42b28bfe48?hl=en
* C++ vs. C# - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c++/t/a7db16921180bbce?hl=en
* Questionable code example in C++ FAQ Lite? - 4 messages, 3 authors
http://groups.google.com/group/comp.lang.c++/t/db4c3e1f63ad2629?hl=en
* CHM version of the C++ FAQ Lite - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c++/t/9acde192f80dc66e?hl=en
* problem with a function template returning a private nested class of a class
template - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c++/t/4be423216e6aa34d?hl=en
* Problem in allocating an array of objects with no default constructor - 4
messages, 3 authors
http://groups.google.com/group/comp.lang.c++/t/8ff1baad02b7428c?hl=en
* Initializers? - 4 messages, 3 authors
http://groups.google.com/group/comp.lang.c++/t/4eabc57174097969?hl=en
* Why do people still use C instead of C++ ? - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c++/t/83ec35fb1ade5f05?hl=en
* bit fields and data structure - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c++/t/f71b2b373b5ef270?hl=en
* Duplicate entry while reading from ifstream into vector - 1 messages, 1
author
http://groups.google.com/group/comp.lang.c++/t/f4242f961463b22e?hl=en
* Is there a faster way to fetch data from stl map? - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c++/t/63653a61e3636884?hl=en
* Using std::lexicographical_compare with ignore case equality doesn't always
work - 4 messages, 3 authors
http://groups.google.com/group/comp.lang.c++/t/dc61ed435800deb4?hl=en
* Error using STL function copy - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c++/t/020430359ddd5edc?hl=en

==============================================================================
TOPIC: luxury Products - www.cicigogo.cn
http://groups.google.com/group/comp.lang.c++/t/0a678e42b28bfe48?hl=en
==============================================================================

== 1 of 1 ==
Date: Sat, Dec 27 2008 11:15 pm
From: online shop


hi
We are supplier in china Footwear Apparel Handbags Jeans&Pants Cap
Accessory(world famous brand)
1) Top quality, reasonable price, safe shipping, and best service
2) Sport shoes for men, women and kids with all sizes available
3) Sport shoes with different colors and styles available in stock
4) The material and size can be required to make in accordance with
customers' requests

Price :8-35usd 6-30EURO 5-30Pounds


size chart
Men Size:
US: 7 8 8.5 9 9.5 10 10.5 11 11.5 12 13 14 15
UK: 6 7 7.5 8 8.5 9 9.5 10 10.5 11 12 13 14
EUR: 40 41 42 42.5 43 44 44.5 45 45.5 46 47.5 48 49
Women Size:
US: 5 5.5 6 6.5 7 7.5 8 8.5
UK: 2.5 3 3.5 4 4.5 5 5.5 6
EUR: 35.5 36 36.5 37.5 38 38.5 39 40


Kid's
US: 11C 12C 12.5C 13C 1Y 1.5Y 2.5Y 3Y
EUR:28 29 30 31 32 33 34 35


Clothing Size:
S M L XL XXL XXXL XXXXL XXXXXL


Footwear
http://www.cicigogo.cn
Apparel
http://www.cicigogo.cn
Handbags
http://www.cicigogo.cn
Jeans&Pants
http://www.cicigogo.cn
Cap
http://www.cicigogo.cn
Accessory
http://www.cicigogo.cn
electronics
http://picasaweb.google.com/cicitrade.eleltronics
CiCi
www.cicigogo.cn
MSN:air jordan
Building Material Market, Goutou Denizen Committee, XiaChen Office
Putian City Chengxiang District CiCi Trade Co., Ltd

==============================================================================
TOPIC: C++ vs. C#
http://groups.google.com/group/comp.lang.c++/t/a7db16921180bbce?hl=en
==============================================================================

== 1 of 1 ==
Date: Sun, Dec 28 2008 12:28 am
From: SG


On 28 Dez., 06:02, tonytech08 <tonytec...@gmail.com> wrote:
> On Dec 27, 6:40 pm, SG <s.gesem...@gmail.com> wrote:
> > On 24 Dez., 17:23, tonytech08 <tonytec...@gmail.com> wrote:
> > > JK and I went round-and-round on this topic in another thread recently
> > > so review that first.
> > I read it but the only thing that stuck was the unfavourable
> > impression you gave.
> About what?

About your understanding of things.

> > So, I checked it again and what I found was
>
> >   lightweight = POD
> >   heavyweight = non-POD
>
> > which is kind of silly.
>
> Well you didn't think about it enough. POD is what you are limited to
> for the concept of "lightweight object" in C++. NOT the other way
> around.
>
> [snipped erroneous conclusion based upon erroneous assumption]

I obviously don't know what you are talking about and I'm guessing I'm
not the only one. So in case you want this thread to have any
responses that are worth reading you might want to reconsider
explaining yourself (w.r.t. lightweight concept) "again" or at least
point to some resource containing the definitions you use.

> > What is remaining is the "layout issue".  What are the compelling
> > reasons for standardizing struct layouts again?  
>
> I won't reiterate those here again. (But I'm not claiming to have been
> thorough in doing that in previous threads).

Ok.

> > The only situation
> > where this may seem to be of use is I/O.  How far do you want this to
> > be restricted?  Do you want to force all implementations to use a
> > certain kind of padding and/or endianness?  What's your proposal?
>
> Proposal? At this juncture, I feel I'm getting around the issue with C+
> + just fine (ignorance is bliss? time will tell!). Further out, I hope
> to use or develop a language that works like I want it to (emphasizes
> features that are important to me). I PAY/PAID for R&D. I may
> investigate R&D grants in the future, but right now I still think I
> can sustain incrementally by delivering software product soon. (Ha!).
> (The "joke" is: I said that 10+ years ago too).

Good luck with that.

Cheers!
SG

==============================================================================
TOPIC: Questionable code example in C++ FAQ Lite?
http://groups.google.com/group/comp.lang.c++/t/db4c3e1f63ad2629?hl=en
==============================================================================

== 1 of 4 ==
Date: Sun, Dec 28 2008 1:26 am
From: Juha Nieminen


Consider the code example here:

http://www.parashift.com/c++-faq-lite/strange-inheritance.html#faq-23.9

It needlessly allocates an object dynamically and, what's worse, it
never deletes it.

Let me emphasize that I understand perfectly that this is done to keep
the example short and simple, and that I understand that *how* the
object is created is completely irrelevant with respect to what the
example is trying to show. (In other words, the allocation of the object
is not the point of the example, but how the object is used in the
subsequent lines.)

However, given that, AFAIK, this FAQ tries to teach good programming
practices in C++, this is a horrible example of that. Even though this
has been done to keep the example simple, there's always the danger of a
beginner programmer seeing this and getting the impression that it's
normal and ok to allocate temporary objects like this and leave them
hanging. Even if allocating the object dynamically would be excusable
(for the sake of simplicity), not deleting it certainly isn't.

(Btw, I once contacted the author of the FAQ about this issue by
email. I clearly explained that I understood why it's done like that,
ie. to keep the example simple, but that I still think it's a bad idea
to teach bad habits to beginner programmers like this. His reply was
extremely disrespectful, arrogant and outright insulting. The example
code was naturally never fixed. I really couldn't understand that kind
of response.)


== 2 of 4 ==
Date: Sun, Dec 28 2008 2:26 am
From: alfps


On 28 Des, 10:26, Juha Nieminen <nos...@thanks.invalid> wrote:
>   Consider the code example here:
>
> http://www.parashift.com/c++-faq-lite/strange-inheritance.html#faq-23.9
>
>   It needlessly allocates an object dynamically and, what's worse, it
> never deletes it.

Yes.


>   Let me emphasize that I understand perfectly that this is done to keep
> the example short and simple, and that I understand that *how* the
> object is created is completely irrelevant with respect to what the
> example is trying to show. (In other words, the allocation of the object
> is not the point of the example, but how the object is used in the
> subsequent lines.)
>
>   However, given that, AFAIK, this FAQ tries to teach good programming
> practices in C++, this is a horrible example of that. Even though this
> has been done to keep the example simple, there's always the danger of a
> beginner programmer seeing this and getting the impression that it's
> normal and ok to allocate temporary objects like this and leave them
> hanging. Even if allocating the object dynamically would be excusable
> (for the sake of simplicity), not deleting it certainly isn't.

You do have a point.

Instead of pointers, this example should simply use references.


>   (Btw, I once contacted the author of the FAQ about this issue by
> email. I clearly explained that I understood why it's done like that,
> ie. to keep the example simple, but that I still think it's a bad idea
> to teach bad habits to beginner programmers like this. His reply was
> extremely disrespectful, arrogant and outright insulting. The example
> code was naturally never fixed. I really couldn't understand that kind
> of response.)

Marshall Cline is one of the most courteous and well-mannered persons
on the face of the planet, so I don't understand this, but I suspect
some Communication Failure(TM).

Unfortunately I'm on Christmas holiday and so I don't have a direct e-
mail address for Marshall here, and as I recall he has a bouncer on
the one given on the FAQ site, where you get an automatic reply and
have to confirm that you're not a spammer. But anyway I'm CC-ing this
to that address; if it manages to sneak through the anti-spam measures
I'm sure Marshall will fix things if he's able to.

Cheers & hth.,

- Alf


== 3 of 4 ==
Date: Sun, Dec 28 2008 5:47 am
From: James Kanze


On Dec 28, 10:26 am, Juha Nieminen <nos...@thanks.invalid> wrote:
> Consider the code example here:

> http://www.parashift.com/c++-faq-lite/strange-inheritance.html#faq-23.9

> It needlessly allocates an object dynamically and, what's
> worse, it never deletes it.

So what? It's only an example, displaying a particular problem.

> Let me emphasize that I understand perfectly that this is done
> to keep the example short and simple, and that I understand
> that *how* the object is created is completely irrelevant with
> respect to what the example is trying to show. (In other
> words, the allocation of the object is not the point of the
> example, but how the object is used in the subsequent lines.)

So what's the point?

> However, given that, AFAIK, this FAQ tries to teach good
> programming practices in C++, this is a horrible example of
> that.

In what way?

> Even though this has been done to keep the example simple,
> there's always the danger of a beginner programmer seeing this
> and getting the impression that it's normal and ok to allocate
> temporary objects like this and leave them hanging. Even if
> allocating the object dynamically would be excusable (for the
> sake of simplicity), not deleting it certainly isn't.

Even beginning programmers write code more complex than the
example. And are capable of understanding that it is only an
example. Throwing the delete in there wouldn't hurt, but it
would raise a number of other issues, irrelevant to the question
being discussed. (Base doesn't have a virtual destructor, for
example.) You could also define the object as a local
variable---that's probably what I would have done---but you have
to recognize the fact that when inheritance is involved, local
variables are the exception, not the rule. All in all, the
example is a good compromise.

--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34


== 4 of 4 ==
Date: Sun, Dec 28 2008 7:07 am
From: Juha Nieminen


James Kanze wrote:
> On Dec 28, 10:26 am, Juha Nieminen <nos...@thanks.invalid> wrote:
>> Consider the code example here:
>
>> http://www.parashift.com/c++-faq-lite/strange-inheritance.html#faq-23.9
>
>> It needlessly allocates an object dynamically and, what's
>> worse, it never deletes it.
>
> So what? It's only an example, displaying a particular problem.

Can't you read the entire post before answering? I explained the
reason why I consider it a dubious example.

>> Let me emphasize that I understand perfectly that this is done
>> to keep the example short and simple, and that I understand
>> that *how* the object is created is completely irrelevant with
>> respect to what the example is trying to show. (In other
>> words, the allocation of the object is not the point of the
>> example, but how the object is used in the subsequent lines.)
>
> So what's the point?

Do you only read one paragraph at a time when you answer to someone's
post?

>> However, given that, AFAIK, this FAQ tries to teach good
>> programming practices in C++, this is a horrible example of
>> that.
>
> In what way?

It seems to be so (given that I explain it immediately after that
paragraph).

> Even beginning programmers write code more complex than the
> example. And are capable of understanding that it is only an
> example.

What does it even mean that "it is only an example"? Exactly which
part of it is "only an example" which should not be taken literally? All
of it? Part of it? Which part?

Exactly how is the beginner programmer supposed to know that "btw,
this part is only for the sake of an example; you should not do this in
actual code"? Wouldn't it be better to simply avoid giving as example
code which should not be written?

==============================================================================
TOPIC: CHM version of the C++ FAQ Lite
http://groups.google.com/group/comp.lang.c++/t/9acde192f80dc66e?hl=en
==============================================================================

== 1 of 1 ==
Date: Sun, Dec 28 2008 2:38 am
From: Lawand


Don't get me wrong, I have talked to the author of the FAQ and we both
decided that there should be a solution to keeping the CHM version up-
to-date.
so I decided to give a link to a page in my blog which will contain
the latest version of the CHM.
and this indirection also helps users post Errata or other requests.
and also helps me change the link in case I hosted the file on another
hosting service in case my monthly bandwidth was consumed.

BTW, did you notice that the blog is ad-free?

==============================================================================
TOPIC: problem with a function template returning a private nested class of a
class template
http://groups.google.com/group/comp.lang.c++/t/4be423216e6aa34d?hl=en
==============================================================================

== 1 of 1 ==
Date: Sun, Dec 28 2008 2:43 am
From: ymost@hotmail.com


On Dec 28, 5:14 am, "jason.cipri...@gmail.com"
<jason.cipri...@gmail.com> wrote:
> On Dec 27, 9:20 pm, ym...@hotmail.com wrote:
>
>
>
> > Hi,
> > I have a class template with two template arguments. It contains a
> > private nested class, and I want a non-member function to return an
> > instance of the nested class:
>
> > //-----------------------------------------------------------------
> > template<typename T1,typename T2> class A {
> >   class B {};
>
> > };
>
> > template<typename T> typename A<T,T>::B func(T x){};
>
> > int main() {
> >   A<int,int> aii;
> >   A<double,double> add;
> >   A<int,double> aid;
> >   A<double,int> adi;
> >   func(1);
> >   return 0;}
>
> > //----------------------------------------------------------------
>
> > (I created some instances of A with different types for testing).
> > Naturally I'm getting a 'class a<int, int>::B is private' error, but I
> > simply cannot succeed in making func a friend function of the class
> > template A. Each reference to func inside the class template A
> > (whether it's a friend declaration or the whole function definition)
> > causes either multiple ambiguous declarations of func, or an access
> > violation because the different instances of A are not friends of each
> > other (at least I think that's the reason).
> > Help will be appreciated.
>
> You have 3 options:
>
> 1. Make the class public.
>
> 2. Make the function a member function.
>
> 3. Declare it as a friend, the syntax is:
>
>   template<typename T1,typename T2> class A {
>     class B {};
>     template<typename T> friend typename A<T,T>::B func(T x);
>   };
>
> Note that that declares func<int> to be a friend of A<float,double>,
> it's not completely strict about the types.
>
> As for your access violation, that's not related to "friend". "Friend"
> tells the compiler not to fail if the friend accesses a private/
> protected member of a class, but it's inconsequential to accessing
> memory outside of your program's boundaries.
>
> Jason

This solves my problem, thanks!

==============================================================================
TOPIC: Problem in allocating an array of objects with no default constructor
http://groups.google.com/group/comp.lang.c++/t/8ff1baad02b7428c?hl=en
==============================================================================

== 1 of 4 ==
Date: Sun, Dec 28 2008 3:01 am
From: yatko


Hi,

I want to allocate an array of interprocess_semaphore object
initialized with 0 counter value. This class is a part of boost
library used for thread synchronization.

class interprocess_semaphore {
public:
// construct/copy/destruct
interprocess_semaphore(int);
~interprocess_semaphore();

// public member functions
void post() ;
void wait() ;
bool try_wait() ;
bool timed_wait(const boost::posix_time::ptime &) ;
};

---

interprocess_semaphore* ready_sem;

ready_sem = new interprocess_semaphore[maxFloor;

Since the class has no default constructor, the compiler gives error.
When I try to use vector, I solve the initialization problem. But at
this time, there is another roblem related with copying semaphores.

vector<interprocess_semaphore> ready_sem;

ready_sem.reserve(maxFloor);

for (int i = 0;i < maxFloor; ++i)
ready_sem.push_back(* new boost::interprocess::interprocess_semaphore
(0));

All I want to do is allocating an array of semephore objects with 0
initial counter value. How can I do that in C++ ?

yatko


== 2 of 4 ==
Date: Sun, Dec 28 2008 4:01 am
From: alfps


On 28 Des, 12:01, yatko <yatkonal...@gmail.com> wrote:
>
> vector<interprocess_semaphore> ready_sem;
>
> ready_sem.reserve(maxFloor);
>
> for (int i = 0;i < maxFloor; ++i)
>         ready_sem.push_back(* new boost::interprocess::interprocess_semaphore
> (0));
>
> All I want to do is allocating an array of semephore objects with 0
> initial counter value. How can I do that in C++ ?

Assuming the objects are copyable (copy constructor and assignment
operator),

vector<interprocess_semaphore> ready_sem( maxFloor, 0 );

Cheers & hth.,

- Alf


== 3 of 4 ==
Date: Sun, Dec 28 2008 4:16 am
From: amrollahi.saeed@gmail.com


On Dec 28, 2:01 pm, yatko <yatkonal...@gmail.com> wrote:
> Hi,
>
> I want to allocate an array of interprocess_semaphore object
> initialized with 0 counter value. This class is a part of boost
> library used for thread synchronization.
>
> class interprocess_semaphore {
> public:
>   // construct/copy/destruct
>   interprocess_semaphore(int);
>   ~interprocess_semaphore();
>
>   // public member functions
>   void post() ;
>   void wait() ;
>   bool try_wait() ;
>   bool timed_wait(const boost::posix_time::ptime &) ;
>
> };
>
> ---
>
> interprocess_semaphore* ready_sem;
>
> ready_sem = new interprocess_semaphore[maxFloor;
>
> Since the class has no default constructor, the compiler gives error.
> When I try to use vector, I solve the initialization problem. But at
> this time, there is another roblem related with copying semaphores.
>
> vector<interprocess_semaphore> ready_sem;
>
> ready_sem.reserve(maxFloor);
>
> for (int i = 0;i < maxFloor; ++i)
>         ready_sem.push_back(* new boost::interprocess::interprocess_semaphore
> (0));
>
> All I want to do is allocating an array of semephore objects with 0
> initial counter value. How can I do that in C++ ?
>
> yatko

Hi Yatko
I have the following suggestions for you:
1. If semaphore objects usually have initial value (0), it is better
to declare your class
like this:
class interprocess_semaphore {
public:
interprocess_semaphore(int = 0); // default ctor
// as before
};
2. Of course it is not a good idea, but if you like to use array over
vector, you can use the following code:
interprocess_semaphore** ready_sem = new interprocess_semaphore*
[maxFloor];

for (int i = 0; i < maxFloor; i++) {
interprocess_semaphore* p = new interprocess_semaphore(0);
ready_sem[i] = p;
}

// use array ...

for (int i = 0; i < maxFloor; i++) {
delete ready_sem[i];
}

delete [] ready_sem;

Regards,
- Saeed


== 4 of 4 ==
Date: Sun, Dec 28 2008 4:42 am
From: yatko


Hi all,

Thanks for your postings and I am very sorry that less information.


> Hi Yatko
> I have the following suggestions for you:
> 1. If semaphoreobjectsusually have initial value (0), it is better
> to declare your class
> like this:
>   class interprocess_semaphore {
>   public:
>      interprocess_semaphore(int = 0); // default ctor
>      // as before
>   };


First, the interprocess_class is a part of boost library and it is
designed with one-parameter constructor. I could not have the chance
of redeclare the overall class.


> 2. Of course it is not a good idea, but if you like to usearrayover
> vector, you can use the following code:
>         interprocess_semaphore** ready_sem = new interprocess_semaphore*
> [maxFloor];
>
>         for (int i = 0; i < maxFloor; i++) {
>                 interprocess_semaphore* p = new interprocess_semaphore(0);
>                 ready_sem[i] = p;
>         }
>
>         // usearray...
>
>         for (int i = 0; i < maxFloor; i++) {
>                 delete ready_sem[i];
>         }
>
>         delete [] ready_sem;
>
> Regards,
>   - Saeed

Second, I have tried to use vector, but since the class is designed as
noncopyable, the compiler gives errors. Finally, I have decided to use
array of pointers and it works fine.

Thanks


==============================================================================
TOPIC: Initializers?
http://groups.google.com/group/comp.lang.c++/t/4eabc57174097969?hl=en
==============================================================================

== 1 of 4 ==
Date: Sun, Dec 28 2008 5:05 am
From: "mlt"


What is the best way to create objects as private fields that take
arguments?

I have class A that contains an instance of class B. In A's constructor I
would like to control a field in B:

class A {

private:
B b;
int size;

public A(){
size = 22;
b = B(size);
}

};


class B{

public B() {}

public B(int s) {
this.size = s;

}

private:
int size;

}

But is there a more elegant way to do this (without using static const int
size)?

== 2 of 4 ==
Date: Sun, Dec 28 2008 5:39 am
From: "Bill"

"mlt" <asdf@asd.com> wrote in message
news:495779a0$0$90269$14726298@news.sunsite.dk...
> What is the best way to create objects as private fields that take
> arguments?
>
> I have class A that contains an instance of class B. In A's constructor I
> would like to control a field in B:
>
> class A {
>
> private:
> B b;
> int size;
>
> public A(){
> size = 22;
> b = B(size);
> }
>
> };
>
>
> class B{
>
> public B() {}
>
> public B(int s) {
> this.size = s;
>
> }
>
> private:
> int size;
>
> }
>
> But is there a more elegant way to do this (without using static const int
> size)?

I think use of an initializer list (in A's contructor) is more appropriate,
and from your subject line you are apparently onto this.

As it is, your program has a design errors in that in constructing an A
object, Bs default constructor is invoked BEFORE the body of As constructor
is even executed. Your existing constructor for A relies on B having an
appropriate assignment operator.

As constructor should look something like:

A(): size(22), B(size){...}.

For this to work, I think you will need to reorder the private elements of A
since they are allocated in the same order that they are declared--not the
order in which they appear in the initializer list.

Bill


== 3 of 4 ==
Date: Sun, Dec 28 2008 5:41 am
From: "Bill"

By the way, "this" is a pointer in C++ (unlike in Java).

Bill


== 4 of 4 ==
Date: Sun, Dec 28 2008 5:52 am
From: nosbor


//something like this

class B{

public:
B() {}

public:
B(int s_):size(s_) {
}

private:
int size;

} ;

class A {

private:
B b;

public:
A(int size_):b(size_){}

};

int main(int argc, char* argv[])
{
A a(22);

return 0;
}

==============================================================================
TOPIC: Why do people still use C instead of C++ ?
http://groups.google.com/group/comp.lang.c++/t/83ec35fb1ade5f05?hl=en
==============================================================================

== 1 of 1 ==
Date: Sun, Dec 28 2008 5:19 am
From: Laurent Deniau


On 28 déc, 05:54, "jason.cipri...@gmail.com"
<jason.cipri...@gmail.com> wrote:
> On Dec 27, 6:58 pm, Laurent Deniau <Laurent.Den...@gmail.com> wrote:
>
>
>
> > On 27 déc, 20:24, Rolf Magnus <ramag...@t-online.de> wrote:
>
> > > Laurent Deniau wrote:
> > > >> Now, are you saying that, as a conclusion, C++ is better than C
> > > >> (because there's no difference in performance, yet C++ has more
> > > >> features), but programmers still use C just because they're used to?
>
> > > >> And in that case, all newbies should be advised to learn C++, right?
>
> > > > C++ is not a super set of C
>
> > > It can be used as one.
>
> > > > and is much more complex which means that "average" C++ programmers may
> > > > have some difficulty to predict the behavior of their code. There is also
> > > > things which are "easy" to do in C and nearly impossible in C++.
>
> > > Which would that be? Most C code can be put through a C++ compiler with only
> > > a few minor changes.
>
> > I would be very interested (honestly) by the "few minor changes" to
> > apply to COS (C Object System) to be able to compile it with a C++
> > compiler. It compiles with a C99 compiler or even with a C99
> > (standalone) preprocessor and a C89 compiler.
>
> I had wanted to take a stab at it, but:
>
> 1. COS is not actually available on SourceForce except through CVS.
> Not very convenient.

Right (sorry for this), I am working on the tarball for next week. I
still need to improve install/uninstall targets of makefiles and some
minor things.

> 2. The COS Makefiles do not build. It appears you used something like
> autoconf but did not actually include a configure script in CVS.

It's only makefiles, but it requires gmake (tested with gmake 3.81).
There is no configure or so to run.

> The
> compilation instructions in your README are incorrect. After looking
> for the source of the problem and seeing the number of environment
> variables that were not defined (e.g. everything checked for by the
> 'prologue' include file), I gave up.

COS is actually tested on MacOSX and Linux since I don't have access
to other architectures. Makefiles are not portable to Windows unless
you install cygwin or equivalent. The config file are not yet done for
it. Maybe you tried on a yet unsupported architecture? The structure
of the makefile is similar to the makefiles of POCO++.

> 3. While it's certainly an interesting project, you seem to have
> reinvented a serious wheel. If a developer used COS in an application,
> then more likely there were better tools for that developer's job than
> C in the first place.

Like? AFAIK, the COS features are unique in a single "language". The
closest would be a mix between Objective-C, CLOS and Dylan.

> > > > I have been using C++ from 1989 to 2006 and switch back to C for this
> > > > reason once I found the programming techniques that fit my needs. Before
> > > > doing the switch, I used (and abused) templates and I studied in depth the
> > > > C++ object model to understand what I could(n't) do. As already said, the
> > > > best is to use the language that fits your needs.
>
> > > I can see uses of templates even down to the smallest microcontroller
> > > devices (and have actually used them there).
>
> > I didn't say that you can't or it's useless. I just say that I tried
> > to implement some features (e.g. multi-methods, messages) which I
> > consider today to be very important in a language and failed to do it
> > in C++ while it was relatively easy to do in C.
>
> Why did you fail to do it in C++? What specific problems are you
> referring to?

- COS needs a C99 preprocessor. Maybe the next release of C++ will get
the equivalent.

- the object model is completely different from the C++ one and it's
rather difficult to combine the two.

- multi-method would have to deal with lookup, overloading and
templates. This is far beyond the capabilities of my macros.

> Issues with... type checking or something?

no, it's not an issue. C and C++ are close enough on that point. In
particular, all COS objects are structures, which make the objects
system strongly statically typed in both languages except that C++
would provide subtyping while C doesn't.

> It's fairly
> straightforward to compile C with a C++ compiler; most of the changes
> involve adding explicit casts and changing names that are now C++
> keywords (e.g. "class").
>
>
> Most issues are described here:http://docs.hp.com/en/92501-90029/ch01s03.html
> , search the page for "changing your C programs to C++".

This paper is about C89. Nevertheless, I do not use C++ keyword (eg.
self and not this for my receivers).

> C does not have support for multi-methods, nor does C++, in both
> languages you have to emulate them some other way. I can certainly
> imagine various schemes for implementing them in C++; they are
> probably similar to what you did in C.

Probably not. In C++ you must stay compliant with the existing. Issues
are those already mentioned, but also management of multi and virtual
inheritance, portability of "generic" pointers to (member) functions
and template functions, support for meta-classes with the unicity of
the ids (not ensured by C++), etc...

> What is it about C++ that you
> found to be a barrier to implementing these? There are plenty of ways
> to do runtime type checking in C++...

Yes. But the "normal way" in C++ would be double (or more) dispatch on
top of the C++ object model. This is not easy to automatize nor
efficient (this is the way multijava works). The dispatcher of COS is
as fast as C++ virtual member functions on Linux 64bits with gcc4.

> Same deal with messaging systems, which are just as trivial to
> implement in C++ as they are in C.

Not exactly. Dispatch is not the all story and it's far beyond this
thread to explain the all story. In order to get an idea, you can
still read the slides

http://cos.cvs.sourceforge.net/viewvc/cos/CosBase/share/doc/cos/slides-cos.pdf.gz

or the paper (longer, obsolete, but gives an idea)

http://cos.cvs.sourceforge.net/viewvc/cos/CosBase/share/doc/cos/cos-overview.pdf.gz

> Jason
>
> P.S. Just to set the tone, I don't have a problem with C at all, and
> still use it for some applications.

Neither me ;-) I am just looking for the right tool for my need
(numerical computation & simulation).

> Mostly I'm wondering if you've
> actually been having issues with C++, or if the issues are because
> your implementation attempts failed for other reasons.

This is more related to C++. In fact you can also have a look at the
second half of the presentation once you have read the COS
presentation. This is a kind of "motivation for COS".

http://cos.cvs.sourceforge.net/viewvc/cos/CosBase/share/doc/cos/slides-design.pdf.gz

You can also google about "strong typing vs strong checking" to get an
idea why I changed my mind and introduce more dynamics in my code.

a+, ld.

==============================================================================
TOPIC: bit fields and data structure
http://groups.google.com/group/comp.lang.c++/t/f71b2b373b5ef270?hl=en
==============================================================================

== 1 of 1 ==
Date: Sun, Dec 28 2008 5:29 am
From: James Kanze


On Dec 28, 4:08 am, ma740988 <ma740...@gmail.com> wrote:
> On Nov 18, 4:24 am, James Kanze <james.ka...@gmail.com> wrote:
> > Same principle. Basically:

> > enum ControlRegisterMasks
> > {
> > spareMask = 0x1FFFFFFF,
> > addressLine3Mask = 0x20000000,
> > addressLine2Mask = 0x40000000,
> > addressLine1Mask = 0x80000000
> > } ;

> > enum ControlRegisterShiftCounts
> > {
> > spareShiftCount = 0,
> > addressLine3ShiftCount = 29,
> > addressLine2ShiftCount = 30,
> > addressLine1ShiftCount = 31
> > } ;

> > typedef unsigned int /* or uint32_t */ ControlRegister ;

> > int
> > getAddressLine1(
> > ControlRegister reg )
> > {
> > return (reg & addressLine1Mask) >> addressLine1ShiftCount ;
> > }

> > void
> > setAddressLine1(
> > ControlRegister& reg,
> > int value )
> > {
> > reg = (reg & ~addressLine1Mask)
> > | ((value << addressLine1ShiftCount) & addressLine1Mask) ;
> > }

> > // ...

> Hows this link (http://www.open-std.org/jtc1/sc22/wg14/www/docs/ n929.pdf)
> for an idea. I like the concept in the document.

I haven't studied it in detail, but it looks like a proposal for
something to add to the standard. Which I don't think was
accepted. In some ways, it is a solution looking for a
problem. It certainly provides something more directly readable
than the current situation, and it provides a portable syntax.
But hardware I/O registers are by their very nature unportable,
so the portable syntax doesn't buy you much. And it's not as if
bit shifting etc. cause any real problems.

--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

==============================================================================
TOPIC: Duplicate entry while reading from ifstream into vector
http://groups.google.com/group/comp.lang.c++/t/f4242f961463b22e?hl=en
==============================================================================

== 1 of 1 ==
Date: Sun, Dec 28 2008 5:33 am
From: James Kanze


On Dec 28, 4:40 am, alfps <alf.p.steinb...@gmail.com> wrote:
> On 28 Des, 03:42, steve....@gmail.com wrote:
> > string temp;
> > vector< string > lw;
> > //while( readFile && !readFile.eof() ) {
> > while( !readFile.fail() ) {
> > readFile >> temp;
> > cout << "temp is: " << temp << endl;
> > lw.push_back(temp);
> > }

> Consider what happens when the input operation (the >>) fails.
> 'temp' is not changed. The code proceeds, using the old value,
> to output "temp is:" and then to add that old value at the end
> of the vector.

> The idiomatic way to do this relies on implicit conversion to
> bool:

> while( readFile >> temp ) ...

> I think that if I were to use iostreams I'd write it more
> explicitly (I suspect many people using the idiomatic way
> don't understand what it means!),

You might be right. One of the advantages of the idiomatic way
is that it works, even if you don't understand it.

Of course, some people who do understand it still use it,
precisely because it is the idiomatic way.

> e.g.

> for( ;; )
> {
> readFile >> temp;
> if( readFile.fail() ) { break; }
> ...
> }

That's even worse. I do sort of like:

for ( readFile >> temp ; readFile ; readFile >> temp ) ...

But in the end, the advantage of being idiomatic outweighs the
other advantages.

> Then the ugliness of the code reflects the ugliness of the
> iostream. :-)

The problem is that nothing better has been proposed. (I/O is a
difficult problem, because it involves side effects which may
fail.)

--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

==============================================================================
TOPIC: Is there a faster way to fetch data from stl map?
http://groups.google.com/group/comp.lang.c++/t/63653a61e3636884?hl=en
==============================================================================

== 1 of 1 ==
Date: Sun, Dec 28 2008 5:38 am
From: James Kanze


On Dec 27, 8:24 pm, blargg....@gishpuppy.com (blargg) wrote:
> tni wrote:

> [...]> struct hash {
> > size_t operator()(int a) const {
> > a = (a ^ 61) ^ (a >> 16);
> > a = a + (a << 3);
> > a = a ^ (a >> 4);
> > a = a * 0x27d4eb2d;
> > a = a ^ (a >> 15);
> > return a;
> > }
> > };

> [...]

> Your hash function would be more portable if you used unsigned
> int, since signed int can overflow in the expressions you use.

More to the point: how are the integer values distributed. If
they're dense, then just using an std::vector would be even
better than a hash table. If they're more or less randomly
distributed, just returning the integral value, converted to
size_t, would be a lot faster than his code, and just as
effective. (His function is really a good example of how not to
implement a hash function.)

--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

==============================================================================
TOPIC: Using std::lexicographical_compare with ignore case equality doesn't
always work
http://groups.google.com/group/comp.lang.c++/t/dc61ed435800deb4?hl=en
==============================================================================

== 1 of 4 ==
Date: Sun, Dec 28 2008 5:44 am
From: Alex Buell


The short snippet below demonstrates the problem I'm having with
std::lexicographical_compare() in that it does not reliably work!

#include <iostream>
#include <vector>
#include <ctype.h>

bool compare_ignore_case_equals(char c1, char c2)
{
return toupper(c1) == toupper(c2);
}

bool compare_ignore_case_less(char c1, char c2)
{
return toupper(c1) < toupper(c2);
}

int main(int argc, char *argv[])
{
std::vector<std::string> args(argv + 1, argv + argc);
const char *words[] =
{
"add", "del", "new", "help"
};

std::vector<std::string> list(words, words + (sizeof words / sizeof words[0]));
std::vector<std::string>::iterator word = list.begin();
while (word != list.end())
{
std::cout << "Testing " << *word << " = " << args[0];
if (std::lexicographical_compare(
word->begin(), word->end(),
args[0].begin(), args[0].end(),
compare_ignore_case_equals))
{
std::cout << " found!\n";
break;
}

std::cout << "\n";
word++;
}
}

Here's an example:

./quick new
Testing add = new
Testing del = new found!

That simply cannot be correct, what is it that I've done wrongly? Thanks
--
http://www.munted.org.uk

Fearsome grindings.

== 2 of 4 ==
Date: Sun, Dec 28 2008 6:09 am
From: Pete Becker


On 2008-12-28 08:44:14 -0500, Alex Buell <alex.buell@munted.org.uk> said:

> The short snippet below demonstrates the problem I'm having with
> std::lexicographical_compare() in that it does not reliably work!
> [code snipped]
> if (std::lexicographical_compare(
> word->begin(), word->end(),
> args[0].begin(), args[0].end(),
> compare_ignore_case_equals))

First, remove compare_ignore_case_equals and try again. You'll get
similar problems. Then read about lexicographical_compare and what its
return value means.

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

== 3 of 4 ==
Date: Sun, Dec 28 2008 7:12 am
From: Alex Buell


On Sun, 28 Dec 2008 09:09:32 -0500, I waved a wand and this message
magically appears in front of Pete Becker:

> > if (std::lexicographical_compare(
> > word->begin(), word->end(),
> > args[0].begin(), args[0].end(),
> > compare_ignore_case_equals))
>
> First, remove compare_ignore_case_equals and try again. You'll get
> similar problems. Then read about lexicographical_compare and what
> its return value means.

I've now switched to using this:

#include <string.h>
#include <string>

inline int strcasecmp(const std::string& s1, const std::string& s2)
{
return strcasecmp(s1.c_str(), s2.c_str());
}

This leverages C++'s ability to overload functions and works better.

stricmp() isn't standard whilst strcasecmp() is standard ANSI/ISO. Some
posters have mentioned using stricmp() instead of strcasecmp(), which
happens not to be the correct answer. Why?
--
http://www.munted.org.uk

Fearsome grindings.

== 4 of 4 ==
Date: Sun, Dec 28 2008 7:33 am
From: "Daniel T."


In article <20081228134414.4b9220f0@lithium.local.net>,
Alex Buell <alex.buell@munted.org.uk> wrote:

> The short snippet below demonstrates the problem I'm having with
> std::lexicographical_compare() in that it does not reliably work!
>
> #include <iostream>
> #include <vector>
> #include <ctype.h>
>
> bool compare_ignore_case_equals(char c1, char c2)
> {
> return toupper(c1) == toupper(c2);
> }
>
> bool compare_ignore_case_less(char c1, char c2)
> {
> return toupper(c1) < toupper(c2);
> }
>
> int main(int argc, char *argv[])
> {
> std::vector<std::string> args(argv + 1, argv + argc);
> const char *words[] =
> {
> "add", "del", "new", "help"
> };
>
> std::vector<std::string> list(words, words + (sizeof words / sizeof
> words[0]));
> std::vector<std::string>::iterator word = list.begin();
> while (word != list.end())
> {
> std::cout << "Testing " << *word << " = " << args[0];
> if (std::lexicographical_compare(
> word->begin(), word->end(),
> args[0].begin(), args[0].end(),
> compare_ignore_case_equals))
> {
> std::cout << " found!\n";
> break;
> }
>
> std::cout << "\n";
> word++;
> }
> }

Why are you using compare_ignore_case_equals as your binary predicate?

--
Perfection is achieved, not when there is nothing more to add,
but when there is nothing left to take away.
-- Antoine de Saint-Exupery

==============================================================================
TOPIC: Error using STL function copy
http://groups.google.com/group/comp.lang.c++/t/020430359ddd5edc?hl=en
==============================================================================

== 1 of 1 ==
Date: Sun, Dec 28 2008 7:18 am
From: arkady.karpman@gmail.com


Hello,

During compilation of code :
std::copy(AgentID_To_AgentStruct.begin(),AgentID_To_AgentStruct.end
(),Local_AgentID_To_AgentStruct.begin());

I got error

Error 125 error C2582: 'operator =' function is unavailable in
'std::pair<_Ty1,_Ty2>' D:\Program Files\Microsoft Visual Studio 8\VC
\include\xutility 2266

I am using VC7++.

Thanks

Arkady


==============================================================================

You received this message because you are subscribed to the Google Groups "comp.lang.c++"
group.

To post to this group, visit http://groups.google.com/group/comp.lang.c++?hl=en

To unsubscribe from this group, send email to comp.lang.c+++unsubscribe@googlegroups.com

To change the way you get mail from this group, visit:
http://groups.google.com/group/comp.lang.c++/subscribe?hl=en

To report abuse, send email explaining the problem to abuse@googlegroups.com

==============================================================================
Google Groups: http://groups.google.com/?hl=en

No comments: