comp.lang.c++
http://groups.google.com/group/comp.lang.c++?hl=encomp.lang.c++@googlegroups.com
Today's topics:
* cast/assignement operators - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/00280114b34902eb?hl=en
* Strooustrup - Hello World exercise - 4 messages, 2 authors
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/082118a58f35476a?hl=en
* C/C++ language proposal: Change the 'case expression' from "integral
constant-expression" to "integral expression" - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/a6452a6641b1fc5b?hl=en
* dynamic array and constructors - 2 messages, 2 authors
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/24c7ef3e322053f1?hl=en
* solving circular dependencies with class only delcared in .h - 1 messages, 1
author
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/652550d4b8a6f0f8?hl=en
* looking for elegant C++ abstraction around pthread_key_t... - 1 messages, 1
author
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/92098dc36b54f96a?hl=en
* How to write a binder3 tempalte function? - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/216f4e8937bbbf4a?hl=en
* allocate memory of derived class - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/87fc908ed9682594?hl=en
* Variable Block Text File - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/c53528aeee514123?hl=en
* Insert static array of struct in a vector - 4 messages, 2 authors
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/67f0d0e0bb28dd7a?hl=en
* Question about creating a struct of flags in c++ - 3 messages, 2 authors
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/aded373b78039bdf?hl=en
* List erase iterator outside range - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/25a39eff0031f895?hl=en
* vector<const T(*)> vs. vector<T(*)> - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/8dca9788b8075995?hl=en
* opening jpeg file in c++ - 2 messages, 2 authors
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/ee4a622091cbf4cb?hl=en
* Is c++ only better c ? - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/38527e42967dc124?hl=en
* WORD TO PDF CONVERTER ! - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/aa74516e119018a7?hl=en
==============================================================================
TOPIC: cast/assignement operators
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/00280114b34902eb?hl=en
==============================================================================
== 1 of 1 ==
Date: Thurs, Oct 30 2008 11:48 pm
From: Paavo Helde
John Doe <mosfet@anonymous.org> kirjutas:
> .rhavin grobert wrote:
>> On 30 Okt., 12:06, Sam <s...@email-scan.com> wrote:
>>> Having said all this, after going through something similar myself,
>>> converting a bunch of code that used MS's gawdawful CString,
>>
>> just curious: what's wrong with CString?
> Have you ever tried to write code on multiplatform ?
> Windows, Windows CE, Symbian, iPhone, ...
Been there, done that. Most cumbersome was to wrap CTime and CFile.
Concerning CString, however, I second Sam in that it should just be
replaced by std::string and all compile errors fixed. The missing methods
(what they might be? OemToAnsi()? Right()?) should be just replaced by free
functions.
> I think you have you answer.
> and the raw std::string is really limited compared to CString that's why
> I am using CStdString.
Nah, from my viewpoint it is CString what is rather limited ;-) It even
does not have find_first_not_of()!
Paavo
==============================================================================
TOPIC: Strooustrup - Hello World exercise
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/082118a58f35476a?hl=en
==============================================================================
== 1 of 4 ==
Date: Fri, Oct 31 2008 1:52 am
From: Juan Antonio Zaratiegui Vallecillo
Eberhard Schefold wrote:
> Juan Antonio Zaratiegui Vallecillo wrote:
>
>> * What does std::cout mean or represent?
>> * What does << mean or represent?
>> * Whta does std::endl mean or represent?
>>
>> Once you have answered those questions, you will know the answer to
>> your problem.
>
> I'm not sure whether you've really noticed the "Do not change main() in
> any way" part.
Oh sorry, you are right. I thought I had seen the usual homework question
== 2 of 4 ==
Date: Thurs, Oct 30 2008 1:38 pm
From: arnuld
> On Fri, 31 Oct 2008 09:52:36 +0100, Juan Antonio Zaratiegui Vallecillo
> Oh sorry, you are right. I thought I had seen the usual homework question
I don't get homework . I am no longer a kid ;)
--
www.lispmachine.wordpress.com
my email is @ the above blog.
Google Groups a.k.a "Spammer's Paradise" is Blocked.
== 3 of 4 ==
Date: Thurs, Oct 30 2008 1:41 pm
From: arnuld
> On Thu, 30 Oct 2008 11:51:24 -0500, A. Bolmarcich wrote:
> In your opening post to this thread you mentioned "Section 10.6,
> Exercise 15". Because chapter 10 is about Classes you need to know
> how to write classes to be able to do the exercises for that chapter.
Actually, I wanted to start my abandoned learning of C++ and my
friend's Stroustrup was lying in front of me on my office desk. My
experience has taught me I can not learn programming my following a book
from cover to cover. So I opened the book at some random place and tried
to solve the exercise that came in front of me.
> Informataion needed to do the exercise is in the subsection on
> Construction and Destruction.
How about this:
#include <iostream>
class Useless
{
public:
Useless() { std::cout << "Initialize" << std::endl; }
~Useless() { std::cout << "Clean up" << std::endl; }
};
Useless obj_of_useless;
int main()
{
std::cout << "Hello World!" << std::endl;
return 0;
}
=========================== OUTPUT ====================================
[arnuld@dune cpp]$ g++ -ansi -pedantic -Wall -Wextra 10-6_15.cpp
[arnuld@dune cpp]$ ./a.out
Initialize
Hello World!
Clean up
[arnuld@dune cpp]$
--
www.lispmachine.wordpress.com
my email is @ the above blog.
Google Groups a.k.a "Spammer's Paradise" is Blocked.
== 4 of 4 ==
Date: Fri, Oct 31 2008 2:27 am
From: Juan Antonio Zaratiegui Vallecillo
arnuld wrote:
>> On Fri, 31 Oct 2008 09:52:36 +0100, Juan Antonio Zaratiegui Vallecillo
>
>> Oh sorry, you are right. I thought I had seen the usual homework question
>
>
> I don't get homework . I am no longer a kid ;)
>
>
Lucky you! I am 45 and I do get full loads of homework. I work at home ;-)
==============================================================================
TOPIC: C/C++ language proposal: Change the 'case expression' from "integral
constant-expression" to "integral expression"
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/a6452a6641b1fc5b?hl=en
==============================================================================
== 1 of 1 ==
Date: Fri, Oct 31 2008 1:56 am
From: Hendrik Schober
Keith Thompson wrote:
> Hendrik Schober <spamtrap@gmx.de> writes:
>> Keith Thompson wrote:
>>> "robertwessel2@yahoo.com" <robertwessel2@yahoo.com> writes:
>>>> On Oct 28, 7:42 pm, JoelKatz <dav...@webmaster.com> wrote:
>>>>> What will be next? "case >=7:"?
>>>> Frankly I think ranges on the case constant expressions would be a
>>>> more useful addition while staying with the basic philosophy of the C
>>>> switch statement. IOW, "case 2...5:", or something along those
>>>> lines. But still not something I'm loosing sleep over...
>>> Then programmers will inevitably write
>>> case 'A' ... 'Z':
>>> which is non-portable (under EBCDIC it matches '\' and '}').
>> And why exactly would that be worse than an 'if'-'else' chain
>> relying on ASCII?
>
> It wouldn't. [...]
Then I don't see how your above argument is valid.
Schobi
==============================================================================
TOPIC: dynamic array and constructors
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/24c7ef3e322053f1?hl=en
==============================================================================
== 1 of 2 ==
Date: Fri, Oct 31 2008 1:42 am
From: Urs Thuermann
I have some old code I've written several years ago that doesn't
compile with newer versions of GCC. The code allocates an array of
objects that need to be initialized by calling a constructor with one
argument:
class B;
class A {
B *b;
public:
A(B *p) : b(p) {}
};
class B {
public:
void foo() {
// this declaration is ok
A a(this);
// the following causes an error with newer GCC:
// error: ISO C++ forbids initialization in array new
A *arr = new A[10](this);
}
};
int main()
{
B b;
}
This worked with g++ until version 3.3.x, but not since 3.4.x. The
problem is in the expression new A[10](this), since according to GCC,
initialization in array new is forbidden.
How would I initialize the array elements in ISO C++?
urs
== 2 of 2 ==
Date: Fri, Oct 31 2008 2:34 am
From: Maxim Yegorushkin
On Oct 31, 8:42 am, Urs Thuermann <u...@janus.isnogud.escape.de>
wrote:
> I have some old code I've written several years ago that doesn't
> compile with newer versions of GCC. The code allocates an array of
> objects that need to be initialized by calling a constructor with one
> argument:
>
> class B;
>
> class A {
> B *b;
>
> public:
> A(B *p) : b(p) {}
> };
>
> class B {
>
> public:
> void foo() {
> // this declaration is ok
> A a(this);
>
> // the following causes an error with newer GCC:
> // error: ISO C++ forbids initialization in array new
> A *arr = new A[10](this);
> }
> };
>
> int main()
> {
> B b;
> }
>
> This worked with g++ until version 3.3.x, but not since 3.4.x. The
> problem is in the expression new A[10](this), since according to GCC,
> initialization in array new is forbidden.
>
> How would I initialize the array elements in ISO C++?
There is no way to specify constructor arguments when using the array
version of new. The default constructor must be available.
Please see the older thread
http://groups.google.co.uk/group/comp.lang.c++.moderated/browse_frm/thread/18f1c9313d32d315
for more information.
--
Max
==============================================================================
TOPIC: solving circular dependencies with class only delcared in .h
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/652550d4b8a6f0f8?hl=en
==============================================================================
== 1 of 1 ==
Date: Fri, Oct 31 2008 2:21 am
From: Marcel Müller
Mosfet schrieb:
> IS there another way to solve this and to keep implementation only in .h ?
Why do you want to have the implementation in .h. This requires at least
that all of your functions are declared inline (implicitely or
explicitely). If the compiler cares about that is another question, but
at least it blows up the compile time of your project significantly.
If you have a cyclic dependancy of the /declaration/ of your classes
e.g. because of the use of certain smart pointers like intrusive_ptr,
then you have a serious problem. If only the implementaions depend on
each other you have no problem.
Marcel
==============================================================================
TOPIC: looking for elegant C++ abstraction around pthread_key_t...
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/92098dc36b54f96a?hl=en
==============================================================================
== 1 of 1 ==
Date: Fri, Oct 31 2008 2:25 am
From: Maxim Yegorushkin
On Oct 30, 11:48 pm, "Chris M. Thomasson" <n...@spam.invalid> wrote:
> Here is what I am playing around with now:
[]
Have you looked at http://www.boost.org/doc/libs/1_36_0/doc/html/thread/thread_local_storage.html
?
--
Max
==============================================================================
TOPIC: How to write a binder3 tempalte function?
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/216f4e8937bbbf4a?hl=en
==============================================================================
== 1 of 1 ==
Date: Fri, Oct 31 2008 2:44 am
From: Maxim Yegorushkin
On Oct 31, 2:39 am, Hill <zhubi...@gmail.com> wrote:
> This is an exercise on TCPL:
> Write a b i n d e r 3 () that binds the second and third arguments of
> a threeargument function to produce a unary predicate. Give an example
> where b i n d e r 3 () is a useful function.
> And i got a solution from << C++ solutions>>:
>
> template<typename FO>
> struct binder2_3
> {
> typedef typename FO::result_type result_type;
> typedef typename FO::first_argument first_argument;
> binder2_3(const FO& fo,
> typename FO::second_argument& a2,
> typename FO::third_argument& a3)
> :fo_(fo), a2_(a2), a3_(a3){}
> result_type operator()(first_argument a1){
> return fo_(a1, a2_, a3_);
> }
> private:
> FO fo_;
> const typename FO::second_argument a2_;
> const typename FO::third_argument a3_;};
>
> template<typename FO, typename P2, typename P3> inline
> binder2_3<FO> binder3(const FO& fo, const P2& a2, const P3& a3){
> return binder2_3<FO>(fo, a2, a3);
>
> }
>
> I can't understand the followingn sentence:
> typedef typename FO::result_type result_type;
> It require FO has a member named result_type ?
It requires FO to have a type member named result_type: typedef,
struct, class or union.
> This is a too restrict rule.
> Could someone give an explaination?
This is because your binder object wraps the call to the underlying
functor. The binder has to return the result of the functor call,
therefore to be able to declare the type of the return value of
binder::operator() it needs to know the type of the return value of
the underlying functor.
--
Max
==============================================================================
TOPIC: allocate memory of derived class
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/87fc908ed9682594?hl=en
==============================================================================
== 1 of 1 ==
Date: Fri, Oct 31 2008 2:51 am
From: Maxim Yegorushkin
On Oct 30, 11:43 pm, Pete Becker <p...@versatilecoding.com> wrote:
> On 2008-10-30 18:00:18 -0400, Salt_Peter <pj_h...@yahoo.com> said:
>
>
>
> >> template<class T>
>
> > should really be:
> > template< typename T >
>
> I guess I'll have to go through the C++ standard and change every
> template declaration to use "typename" instead of "class".
>
> This is a style thing. Some people prefer "typename" for unfathomable
> reasons, and right-thinking programmers use "class".
I agree with you. "class" is preferable for pragmatic reasons: easier
to type, occupies less real estate in the source files and means the
very same thing in this context.
--
Max
==============================================================================
TOPIC: Variable Block Text File
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/c53528aeee514123?hl=en
==============================================================================
== 1 of 1 ==
Date: Fri, Oct 31 2008 3:33 am
From: James Kanze
On Oct 30, 8:14 pm, Juha Nieminen <nos...@thanks.invalid> wrote:
> Richard Herring wrote:
> > A value is just a value, it isn't "binary" any more than it
> > is "hexadecimal".
> True, but it's difficult to talk about values and their
> storage when the terminology is so confusing.
> "Hexadecimal" refers quite unambiguously to the (usually
> ascii) representation of a numerical value (in base 16). The
> term "binary" is more complicated.
> In theory when you say "the number is stored in binary" it
> might refer to one of two things:
> 1) It's stored in base-2 representation. That is, the number
> is stored by writing a combination of the two characters '0'
> and '1'.
That is, actually, what is required by the C++ standard.
Of course, since only two characters are involved, a character
encoding using just one bit (rather than the usual 7, 8 or more)
is sufficient, and used by all of the implementations I've ever
encountered.
(Sort of a half :-). Just thought I'd add to the confusion, for
the fun of it.)
> 2) It's stored in the same way as it's stored in memory, in
> other words, as a series of octets. In other words, it's
> stored in "raw" format, without any conversion or
> representation in ascii.
I like the word "raw". Or "machine" or "hardware" representation.
The C++ standard requires this to be a pure binary
representation (and I don't think the intent is to require
ASCII).
Of course, all of the standard requirements are "as if"; an
implementation can use base 10, as long as it implements &, |, ^
and ~ in a manner that they behave "as if" the representation
were base 2.
> Thus the term "binary" is used with two different meanings: In
> some contexts it talks about base-2 (ascii) representation, in
> other contexts it talks about raw, unconverted byte values
> (eg. when saying "open the file in binary mode). These two
> things have basically nothing to do with each other, except
> that they share the name "binary".
And that they are both demonstrably base 2. (Consider the
behavior of |, &, ^ and ~.)
> Maybe this is the reason why it seems that some people get
> even more confused and think "hexadecimal" refers to what
> usually is meant with "binary" (in the second meaning).
Since most modern machines are byte oriented, maybe we should
call machine format base 256.
--
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: Insert static array of struct in a vector
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/67f0d0e0bb28dd7a?hl=en
==============================================================================
== 1 of 4 ==
Date: Fri, Oct 31 2008 3:37 am
From: John Doe
Hi,
I have a static array of struct defined like this :
CViewMgr::ViewInfo g_ViewInfo[] =
{
{ EMainView, ECreateOnce, IDR_MAINFRAME, RUNTIME_CLASS(CMainView),
NULL,0, 0 },
{ EWelcomeView, ECreateAndDestroy, IDR_MENU_OKCANCEL,
RUNTIME_CLASS(CWelcomeView), NULL,0, 0 },
};
I would like to put all these declarations in a vector how can I do it ?
typedef std::vector<ViewInfo> ViewList;
ViewList viewList;
soemthing like :
for (int i = 0; i < _countof(g_ViewInfo); i++)
viewList.push_back(g_ViewInfo[i]);
But I am sure there is an easier way, maybe I should call reserve before ?
== 2 of 4 ==
Date: Fri, Oct 31 2008 3:40 am
From: Maxim Yegorushkin
On Oct 31, 10:37 am, John Doe <mos...@anonymous.org> wrote:
> Hi,
>
> I have a static array of struct defined like this :
>
> CViewMgr::ViewInfo g_ViewInfo[] =
> {
> { EMainView, ECreateOnce, IDR_MAINFRAME, RUNTIME_CLASS(CMainView),
> NULL,0, 0 },
> { EWelcomeView, ECreateAndDestroy, IDR_MENU_OKCANCEL,
> RUNTIME_CLASS(CWelcomeView), NULL,0, 0 },
>
> };
>
> I would like to put all these declarations in a vector how can I do it ?
> typedef std::vector<ViewInfo> ViewList;
> ViewList viewList;
>
> soemthing like :
>
> for (int i = 0; i < _countof(g_ViewInfo); i++)
> viewList.push_back(g_ViewInfo[i]);
>
> But I am sure there is an easier way, maybe I should call reserve before ?
Try this:
ViewList viewList(
g_ViewInfo
, g_ViewInfo + sizeof g_ViewInfo / sizeof *g_ViewInfo
);
--
Max
== 3 of 4 ==
Date: Fri, Oct 31 2008 3:52 am
From: John Doe
Maxim Yegorushkin wrote:
> On Oct 31, 10:37 am, John Doe <mos...@anonymous.org> wrote:
>> Hi,
>>
>> I have a static array of struct defined like this :
>>
>> CViewMgr::ViewInfo g_ViewInfo[] =
>> {
>> { EMainView, ECreateOnce, IDR_MAINFRAME, RUNTIME_CLASS(CMainView),
>> NULL,0, 0 },
>> { EWelcomeView, ECreateAndDestroy, IDR_MENU_OKCANCEL,
>> RUNTIME_CLASS(CWelcomeView), NULL,0, 0 },
>>
>> };
>>
>> I would like to put all these declarations in a vector how can I do it ?
>> typedef std::vector<ViewInfo> ViewList;
>> ViewList viewList;
>>
>> soemthing like :
>>
>> for (int i = 0; i < _countof(g_ViewInfo); i++)
>> viewList.push_back(g_ViewInfo[i]);
>>
>> But I am sure there is an easier way, maybe I should call reserve before ?
>
> Try this:
>
> ViewList viewList(
> g_ViewInfo
> , g_ViewInfo + sizeof g_ViewInfo / sizeof *g_ViewInfo
> );
>
> --
> Max
>
>
>
So I suppose it means I have to put init in constructor because my list
is a variable member.
CViewMgr::CViewMgr():
m_viewList(g_ViewInfo, g_ViewInfo + _countof(g_ViewInfo))
{
}
== 4 of 4 ==
Date: Fri, Oct 31 2008 4:13 am
From: Maxim Yegorushkin
On Oct 31, 10:52 am, John Doe <mos...@anonymous.org> wrote:
> Maxim Yegorushkin wrote:
> > On Oct 31, 10:37 am, John Doe <mos...@anonymous.org> wrote:
> >> Hi,
>
> >> I have a static array of struct defined like this :
>
> >> CViewMgr::ViewInfo g_ViewInfo[] =
> >> {
> >> { EMainView, ECreateOnce, IDR_MAINFRAME, RUNTIME_CLASS(CMainView),
> >> NULL,0, 0 },
> >> { EWelcomeView, ECreateAndDestroy, IDR_MENU_OKCANCEL,
> >> RUNTIME_CLASS(CWelcomeView), NULL,0, 0 },
>
> >> };
>
> >> I would like to put all these declarations in a vector how can I do it ?
> >> typedef std::vector<ViewInfo> ViewList;
> >> ViewList viewList;
>
> >> soemthing like :
>
> >> for (int i = 0; i < _countof(g_ViewInfo); i++)
> >> viewList.push_back(g_ViewInfo[i]);
>
> >> But I am sure there is an easier way, maybe I should call reserve before ?
>
> > Try this:
>
> > ViewList viewList(
> > g_ViewInfo
> > , g_ViewInfo + sizeof g_ViewInfo / sizeof *g_ViewInfo
> > );
>
> > --
> > Max
>
> So I suppose it means I have to put init in constructor because my list
> is a variable member.
>
> CViewMgr::CViewMgr():
> m_viewList(g_ViewInfo, g_ViewInfo + _countof(g_ViewInfo))
> {
>
> }
This syntax invokes the constructor of the vector which accepts two
iterators.
There is also vector::insert() which accepts iterators. It is
perfectly fine to append to an empty vector as well:
viewList.insert(
viewList.end()
, g_ViewInfo
, g_ViewInfo + _countof(g_ViewInfo)
);
--
Max
--
Max
==============================================================================
TOPIC: Question about creating a struct of flags in c++
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/aded373b78039bdf?hl=en
==============================================================================
== 1 of 3 ==
Date: Fri, Oct 31 2008 3:42 am
From: James Kanze
On Oct 30, 4:03 pm, "Plisske...@gmail.com" <Plisske...@gmail.com>
wrote:
> On Oct 30, 9:22 am, Victor Bazarov <v.Abaza...@comAcast.net> wrote:
> > Plisske...@gmail.com wrote:
> > > [..] If I create a class like this:
> > > class myMask {
> > > public:
> > > bool flag1:1;
> > > bool flag2:1;
> > > bool flag3:1;
> > > bool flag4:1;
> > > bool flag5:1;
> > > bool flag6:1;
> > > bool flag7:1;
> > > bool flag8:1;
> > > bool flag9:1;
> > > bool flag10:1;
> > > bool flag11:1;
> > > bool flag12:1;
> > > bool flag13:1;
> > > };
> > > Can I set all the flag to 0 by doing this:
> > > myMask mask;
> > That will leave them undefined. Consider defining the
> > default constructor and the comparison operator.
> > > memset(&mask, '\0', sizeof(myMask));
> > > And can I compare if 2 masks are the same by doing this:
> > > myMask mask1;
> > > myMask mask2;
> > > memcmp(&mask1, &mask2, sizeof(myMask));
> > It is better to have the overloaded operator== in your class.
> In my case, I have this class which only have
> ~200 boolean flags. I am thinking if there is a faster way to
> * initialize all of them to false
Faster than what? I'd expect the compiler to use the fastest
means available on the target hardware for myMask().
> * compare if 2 classes have the same values (the same set of flags are
> set)
Regretfully, there's not real way to compare the values other
than one by one. The compiler is free to introduce padding
where ever it wants. In practice, if you arrange for the total
number of bits to be a multiple of your machine's word size
(with an unsigned pad:n at the end, where n is whatever is
needed), and ensure that the added field is always 0, memcmp
will almost certainly work, even if the standard doesn't
guarantee it.
--
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
== 2 of 3 ==
Date: Fri, Oct 31 2008 3:52 am
From: James Kanze
On Oct 30, 4:03 pm, ".rhavin grobert" <cl...@yahoo.de> wrote:
> On 30 Okt., 06:50, "Plisske...@gmail.com" <Plisske...@gmail.com>
> wrote:
[...]
> > And can I compare if 2 masks are the same by doing this:
> > myMask mask1;
> > myMask mask2;
> > memcmp(&mask1, &mask2, sizeof(myMask));
> try this:
> struct myMask {
> union {
> unsigned int nMask;
> struct {
> bool flag1:1;
> bool flag2:1;
> bool flag3:1;
> bool flag4:1;
> bool flag5:1;
> bool flag6:1;
> bool flag7:1;
> bool flag8:1;
> bool flag9:1;
> bool flag10:1;
> bool flag11:1;
> bool flag12:1;
> bool flag13:1;
> };
> };
> };
> inline bool operator==(myMask const& rm, myMask const& lm)
> {return rm.nMask == lm.nMask;};
Lot's of problems with that.
-- It's not legal C++. Only unions can be anonymous, not
structs.
-- You'll almost certainly end up with undefined behavior using
it; you can't access the nMask element unless it was the
last one written to.
-- If you've written to the flags structure (which you haven't
named), the padding bits may take on any arbitrary values.
Which mean that two equal myMask may have unequald nMask.
-- For up to 16 flags, you're OK, but for more, the unsigned
may be smaller than the struct.
> the union will force your compiler to put all the bits into
> one int.
Not really.
> you can the set the int to 0 to clear all bits and compare the
> ints to compare the masks.
If the int is large enough, this will probably work *IF* he
makes sure that any unused bits in the struct are always 0.
--
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
== 3 of 3 ==
Date: Fri, Oct 31 2008 4:44 am
From: Hendrik Schober
Victor Bazarov wrote:
> Plissken.s@gmail.com wrote:
>> On Oct 30, 9:22 am, Victor Bazarov <v.Abaza...@comAcast.net> wrote:
>>> Plisske...@gmail.com wrote:
>>>> [..] If I create a class like this:
>>>> class myMask {
>>>> public:
>>>> bool flag1:1;
>>>> bool flag2:1;
>>>> bool flag3:1;
>>>> bool flag4:1;
>>>> bool flag5:1;
>>>> bool flag6:1;
>>>> bool flag7:1;
>>>> bool flag8:1;
>>>> bool flag9:1;
>>>> bool flag10:1;
>>>> bool flag11:1;
>>>> bool flag12:1;
>>>> bool flag13:1;
>>>> };
>>>> Can I set all the flag to 0 by doing this:
>>>> myMask mask;
>>> That will leave them undefined. Consider defining the default
>>> constructor and the comparison operator.
>>>
>>>
>>>
>>>> memset(&mask, '\0', sizeof(myMask));
>>>> And can I compare if 2 masks are the same by doing this:
>>>> myMask mask1;
>>>> myMask mask2;
>>>> memcmp(&mask1, &mask2, sizeof(myMask));
>>> It is better to have the overloaded operator== in your class.
>>>
>>> V
>>> --
>>> Please remove capital 'A's when replying by e-mail
>>> I do not respond to top-posted replies, please don't ask
>> Thank you for all the help.
>>
>> In my case, I have this class which only have
>> ~200 boolean flags. I am thinking if there is a faster way to
>> * initialize all of them to false
>> * compare if 2 classes have the same values (the same set of flags are
>> set)
>>
>> Thank you again.
>
> What you could do is have a static object of the same class that you'll
> use as the prototype for initialising, and have the proper padding to
> ensure that all data members are initialised:
>
> struct myLargeClass {
> bool blah : 1; // 1st bit
> bool clah : 1; // 2nd bit
> ...
> bool zlah : 1; // 25th bit
> unsigned padding : 7; // to bring it to 32 bits total
>
> static myLargeClass prototype;
> myLargeClass() {
> if (this != &prototype)
> memset(this, &prototype, sizeof *this);
> }
> };
>
> Statics are always zero-initialised, so 'prototype' is going to contain
> all zeros. Then you can always compare objects using 'memcmp' since
> there will be no uninitialised bits.
>
> Don't forget to define 'prototype' somewhere in your implementation file.
While this works, I wonder what's wrong with 'std::bitset'
that you prefer to do it manually? (I have never used it,
so I don't know what its disadvantages are.)
> V
Schobi
==============================================================================
TOPIC: List erase iterator outside range
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/25a39eff0031f895?hl=en
==============================================================================
== 1 of 1 ==
Date: Fri, Oct 31 2008 3:57 am
From: Hendrik Schober
Krice wrote:
> On 29 loka, 15:31, Marcel Müller <news.5.ma...@spamgourmet.com> wrote:
>> Approximately here I get the first bunch of compiler errors.
>
> Wow, what a surprise!
>
>> So please either post resonable C++ code
>
> Fuck you.
Wow. Someone really needs help here.
Schobi
==============================================================================
TOPIC: vector<const T(*)> vs. vector<T(*)>
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/8dca9788b8075995?hl=en
==============================================================================
== 1 of 1 ==
Date: Fri, Oct 31 2008 4:01 am
From: James Kanze
On Oct 30, 12:04 pm, eiji.anonrem...@googlemail.com wrote:
> I'm facing some uncertainty with const template arguments.
> Maybe someone could explain the general strategy.
> #include <vector>
> int main(int arc, char** argv)
> {
> std::vector<const int> vec;
This is illegal---undefined behavior according to the standard.
It doesn't compile with my compiler (g++, with the usual
options). And whatever happens if it does compile, you can't
count on it.
> const int i = 5;
> vec.push_back(i);
> vec[0] = 4; //const has gone away
Maybe. Or maybe it core dumps. Or maybe just about anything
else. (I would generally expect it not to compile, but the
standard doesn't require an error message.
> std::vector<const int*> pvec;
> const int* pi = new int(5);
> pvec.push_back(pi);
> *(pvec[0]) = 4; // not possible because const, compile error
> return 0;
> }
> From the first impression, it is not possible to create a
> vector of const ints. But you can do it with pointers.
What's in the vector cannot be const. You can create a vector
of non-const pointers to const (which is what you did), but not
of const pointers to anything. (You're probably being confused
by a widespread abuse of language. int const* is not a const
pointer, but a pointer to const. A const pointer would be int*
const or int const* const. More generally, just remember that
the const applies to whatever precedes it.)
--
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: opening jpeg file in c++
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/ee4a622091cbf4cb?hl=en
==============================================================================
== 1 of 2 ==
Date: Fri, Oct 31 2008 4:20 am
From: mohi
hello everyone ,
i am trying to read a jpeg image through c++ but is unable to do so ,
presently i tried it with code in c as i use something like ;
FILE * fp=fopen("./x.jpg","wb");
int c;
do{
read(fp,&c,sizeof(c));
if( c==(int) 0xFF23){
do.....
do....
}
printf("%x",c);
}
while(c!=EOF);
but the problem is the if condition never evalutes to true as i know
that according to the jpeg standard there should be market with value
0xFFD8 and others also .....and also the printf() of integer 'c' as
hex is never displayed it just displays a blank ..
what could be wrong ??
or what is the best way to read a binary file such as an image ??
thanks a lot
mohan gupta
== 2 of 2 ==
Date: Fri, Oct 31 2008 4:36 am
From: Maxim Yegorushkin
On Oct 31, 11:20 am, mohi <mohangupt...@gmail.com> wrote:
> hello everyone ,
>
> i am trying to read a jpeg image through c++ but is unable to do so ,
> presently i tried it with code in c as i use something like ;
>
> FILE * fp=fopen("./x.jpg","wb");
This opens the file for writing. If a file with the same name already
exists its content is erased and the file is treated as a new empty
file.
--
Max
==============================================================================
TOPIC: Is c++ only better c ?
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/38527e42967dc124?hl=en
==============================================================================
== 1 of 1 ==
Date: Fri, Oct 31 2008 5:01 am
From: James Kanze
On Oct 30, 7:55 pm, Juha Nieminen <nos...@thanks.invalid> wrote:
> James Kanze wrote:
> >> The LaTeX equation syntax is *by far* simpler to read and
> >> write by a human.
> > The point is that neither are designed to be read by a
> > human; they are designed to be read my a machine in order to
> > generate output which is read by a human.
> That's like saying that the text you just wrote is not
> designed to be read by a human but by a machine (for the sole
> reason that you are writing it with a machine rather than pen
> and paper).
Yes and no.
Yes in the sense that what you are reading is NOT what I
actually typed. (I only typed a line break between paragraphs,
for example. My editor ensures that the line with is no more
than 64.)
Yes also in the sense that what I typed resulted in a sequence
of bytes, which you read through a program which renders them as
text on the screen. And what you read depends on that renderer;
if it interprets those bytes as EBCDIC, what I've written will
be pretty unreadable.
No, however, in the more important sense that what you are
reading is a very direct, one to one rendering of the bytes in
the file; each byte (or each character) in the file corresponds
to a single text character rendered on your screen or printer.
This is not the case for LaTeX or MathML or XHTML or other
markup languages. More importantly, with the possible exception
of LaTeX, you wouldn't actually type the character sequence
being transmitted, or even necessarily see it. Even with LaTeX,
I suspect that most people will use something like LyX, and
rarely look at or worry about the actual "program" that they've
written.
--
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: WORD TO PDF CONVERTER !
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/aa74516e119018a7?hl=en
==============================================================================
== 1 of 1 ==
Date: Fri, Oct 31 2008 5:01 am
From: Kimo1021
Dear all,
that program converts from word to pdf very easy and free
DOWNLOAD HERE FOR FREE
http://www.ziddu.com/download/2418735/Savefromwiordaspdfformat.rar.html
==============================================================================
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