comp.lang.c++
http://groups.google.com/group/comp.lang.c++?hl=encomp.lang.c++@googlegroups.com
Today's topics:
* cout vs std::cout - 3 messages, 3 authors
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/4f48acdaa9e16cee?hl=en
* unscrambling typeid().name - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/a1dcc8d6a662d966?hl=en
* Using BFD - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/d889b8651eb84cfd?hl=en
* wrapping std::vector<> to track memory usage? - 3 messages, 3 authors
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/03c4b2188e8040c6?hl=en
* Global object initialization - 3 messages, 2 authors
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/4eccf55d938f3bf2?hl=en
* Trying to apply SFINAE - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/2d8ff4d0d6e8c793?hl=en
* How to make non-blocking call to cin? - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/0ab112b61c8dc29e?hl=en
* What's the standard say about this code? - 3 messages, 2 authors
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/ba343bcb425e7e31?hl=en
* passing object reference to the method - 3 messages, 3 authors
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/ce783dea61c7f4b8?hl=en
* how to use libstdc++.so.5 instead of libstdc++.so.6 - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/b79b9c199d58416b?hl=en
* C++ gurus, keywords: programming,search, expertise - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/c7f14464d8307503?hl=en
* ODR: A simple question - 2 messages, 1 author
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/d65f12d76742875b?hl=en
* (&vec)== &vec[0]? - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/d77c87f0acfdcd75?hl=en
==============================================================================
TOPIC: cout vs std::cout
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/4f48acdaa9e16cee?hl=en
==============================================================================
== 1 of 3 ==
Date: Tues, Sep 30 2008 6:18 am
From: ytrembla@nyx.nyx.net (Yannick Tremblay)
In article <gbqvc0$2um$2@cb.generation-online.de>,
Hendrik Schober <spamtrap@gmx.de> wrote:
>Yannick Tremblay wrote:
>> In article <gbqqk9$v30$1@cb.generation-online.de>,
>> Hendrik Schober <spamtrap@gmx.de> wrote:
>>> Yannick Tremblay wrote:
>>>> [Ridiculous example deleted]
>>> No. The next project introduced its string utilities
>>> in a namespace 'Strings'.
>>
>> But the point remains that "Strings" is less clear than "StringUtility".
>>
>> In this particular case, the loss of clarity is probably acceptable
>> but that virtual ban on namespaces is IMO a bad thing because I
>> think it encourages bad naming.
>
> Which ban?
I did write *virtual* ban but sorry, I mean virtual ban of "using
namespace" not on "namespace" themselves.
The exact quote was:
"Most of the time I worked under the rule that using declarations (and
even using directives!) where allowed within any local scopes not
bigger than a function,"
IMO, this amount to a virtual ban. given that function scopes should
hopefully average less than 20 line and that in these 10-20 lines, you
are unlikely to use things from a particular namespace more than 3-5
times, then typing "using namespace String;" takes about as much
typing effort as 3 explicit String::. May almost as well ban them.
Obviously, then might become somewhat useful in 200 liners functions
but of course these should already have been banned well before the
restrictions on "using" was written :-)
Yannick
== 2 of 3 ==
Date: Tues, Sep 30 2008 6:55 am
From: LR
James Kanze wrote:
> On Sep 29, 5:35 am, Rolf Magnus <ramag...@t-online.de> wrote:
>
> [...]
>> A disadvantage of explicitly qualifying with ::std or even
>> with std is that it makes it hard to create your own cout and
>> replace all uses of the standard cout with this one.
>
> I'd say just the opposite. A global search and replace on
> \<std::cout\> will work just fine. A global search and replace
> on \<cout\> will change not only the cout in std, but any other
> cout you happen to have as well. (And of course, if it's
> something special, you probably want to call it something other
> than cout anyway.)
>
>> If you have a
>
>> using std::cout;
>
>> cout << "Hello world\n";
>
>> you can simply replace the using declaration and you're done
>> instead of changing every single occurance of cout in your
>> code.
>
> The problem with this is that it fools the reader. If you see
> cout, and you know that the programmer often makes use of using
> declarations, you'll just assume that it's std::cout. If you
> see std::cout, you know it's std::cout, and if you see
> MyNamespace::cout, you know it isn't.
Sometimes, because of the environment I use I find this little snippet
useful:
namespace non_std { // or whatever namespace you'd like
std::ostream &cout = std::cout;
}
And in other code...
non_std::cout << "something" << std::endl;
When I don't want to write to std::cout for some reason, it's pretty
easy to change non_std::cout to refer to some other stream.
I do have to pay attention to what non_std::cout is.
LR
== 3 of 3 ==
Date: Tues, Sep 30 2008 9:19 am
From: Juha Nieminen
James Kanze wrote:
> I can't think of any really good examples involving
> IO, but to take Juha's example, if you have a 10 line function
> that invokes std::replace in 5 different places, I'd see nothing
> objectionable to a:
> using std::replace ;
> at the top of the function.
So you write 19 characters (plus indentation plus a newline) to save
25 characters, for a total net saving of 6 characters (and only if we
don't count the indentation whitespaces and newline).
I really don't see the point.
==============================================================================
TOPIC: unscrambling typeid().name
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/a1dcc8d6a662d966?hl=en
==============================================================================
== 1 of 1 ==
Date: Tues, Sep 30 2008 6:22 am
From: Marco Manfredini
Deepak Jharodia wrote:
> I'm using a templatized class in GCC based environ
>
> template<class A, class B>
> class foo {...
> ...} F;
>
> Now I want to know that particular instance of this class was
> instantiated with what template arguments. typeid.name() returns a
> strange string with all the info but abbreviated and probably platform
> specific.
> How can I unscramble it and probably use it my program during runtime?
>
For recent versions of GCC, __cxa_demangle unscrambles the typename.
Please see the manual:
http://gcc.gnu.org/onlinedocs/libstdc++/manual/bk01pt12ch39.html
==============================================================================
TOPIC: Using BFD
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/d889b8651eb84cfd?hl=en
==============================================================================
== 1 of 1 ==
Date: Tues, Sep 30 2008 6:55 am
From: Victor Bazarov
Deepak Jharodia wrote:
> On Sep 26, 5:57 pm, Victor Bazarov <v.Abaza...@comAcast.net> wrote:
>> Deepak Jharodia wrote:
>>> I've done some study about BFD(binary file descriptor) library and
>>> have following doubts:
>>> If I inlcude libbfd.a in my final executable can I use this executable
>>> to read it'sown symbol table, by reading libbfd.a? Is it possible? Is
>>> there any other(/better) way to do this?
>> What is your C++ *language* question, again?
>
> Can you please guide me to correct group for this?
I am not sure what the "binary file descriptor" is, but from the word
"file" I can imagine that the first newsgroup you should try is the one
that deals with your OS. Since you didn't say what your OS is, I'll
make a guess that ti's Linux, so try 'comp.os.linux.development.apps'.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
==============================================================================
TOPIC: wrapping std::vector<> to track memory usage?
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/03c4b2188e8040c6?hl=en
==============================================================================
== 1 of 3 ==
Date: Tues, Sep 30 2008 7:00 am
From: jacek.dziedzic@gmail.com
Hi!
I need to be able to track memory usage in a medium-sized
application I'm developing. The only significant (memory-wise) non-
local objects are of two types -- std::vector<> and of a custom class
simple_vector<> that is a hand-rolled substitute for array<>. With the
latter I have code that tracks all allocations and destructions, so I
can account for all the memory.
The question is about std::vector<> -- how can I track memory usage
by individual std::vector's? I'm thinking along the lines of a wrapper
(templated) class, like std::tracked_vector<> which would have the
original std::vector<> as a private member, delegate relevant
operations to the underlying std::vector, while doing the accounting
job behind the scenes.
Are there any particular pitfalls to such a design? Would it suffice
to delegate only the methods I actually use,
like .size(), .reserve(), .at(), [] operators, etc. or would I need to
delegate all possible methods? I fear that since I use the
std::vector's in stl algorithms and other stl containers (vectors of
vectors), I might need to delegate all the iterator stuff and other
methods I don't use directly, is this the case? How do I account for
vectors of vectors, so that I don't bill the same memory twice?
Surely, someone must have gone that route, are there any particular
do's and don'ts there? Is it feasible? I don't want to reinvent the
wheel.
TIA,
- J.
== 2 of 3 ==
Date: Tues, Sep 30 2008 8:29 am
From: Maxim Yegorushkin
On Sep 30, 3:00 pm, jacek.dzied...@gmail.com wrote:
> I need to be able to track memory usage in a medium-sized
> application I'm developing. The only significant (memory-wise) non-
> local objects are of two types -- std::vector<> and of a custom class
> simple_vector<> that is a hand-rolled substitute for array<>. With the
> latter I have code that tracks all allocations and destructions, so I
> can account for all the memory.
>
> The question is about std::vector<> -- how can I track memory usage
> by individual std::vector's? I'm thinking along the lines of a wrapper
> (templated) class, like std::tracked_vector<> which would have the
> original std::vector<> as a private member, delegate relevant
> operations to the underlying std::vector, while doing the accounting
> job behind the scenes.
[]
You could use a custom allocator that would maintain a counter of how
much memory has been allocated. Something like that:
#include <vector>
#include <iostream>
size_t allocated;
void print_allocated(int n)
{
std::cout << n << ": " << allocated << '\n';
}
template<class T>
struct counted_allocator : std::allocator<T>
{
template<class U>
struct rebind { typedef counted_allocator<U> other; };
typedef std::allocator<T> base;
typedef typename base::pointer pointer;
typedef typename base::size_type size_type;
pointer allocate(size_type n)
{
allocated += n * sizeof(T);
return this->base::allocate(n);
}
pointer allocate(size_type n, void const* hint)
{
allocated += n * sizeof(T);
return this->base::allocate(n, hint);
}
void deallocate(pointer p, size_type n)
{
allocated -= n * sizeof(T);
this->base::deallocate(p, n);
}
};
int main()
{
typedef std::vector<int, counted_allocator<int> > IntVec;
print_allocated(0);
{
IntVec v;
v.resize(1000);
print_allocated(1);
v.resize(2000);
print_allocated(2);
IntVec u = v;
print_allocated(3);
}
print_allocated(4);
}
Output:
0: 0
1: 4000
2: 8000
3: 16000
4: 0
--
Max
== 3 of 3 ==
Date: Tues, Sep 30 2008 9:51 am
From: Juha Nieminen
jacek.dziedzic@gmail.com wrote:
> Would it suffice to delegate only the methods I actually use,
> like .size(), .reserve(), .at(), [] operators, etc. or would I need to
> delegate all possible methods?
std::vector itself obviously doesn't require anything about your
delegating functions. You can implement those functions which you need
and leave the rest. (Of course you will find that you will have to keep
adding delegating functions as you start using vector functions in your
code which you weren't using before. But as long as you have access to
the wrapper class, it shouldn't be a huge problem.)
Note, however, that by using this technique you will only be able to
track the amount of space requested from std::vector *explicitly*.
There's no way of knowing how much memory the std::vector is *really*
allocating behind the scenes. Also, even if you were able to do that, it
wouldn't help you knowing the real amount of RAM used. All allocations
have a certain overhead to them, and especially std::vector easily
causes memory fragmentation when it grows, and you might end up having a
significant amount of unused memory which is nevertheless allocated from
the system because of memory fragmentation. In the worst case scenario
the real memory usage of your program (ie. what your program requests
the OS to allocate for it) might be even over double the amount of
memory that you are *explicitly* allocating (and tracking).
Explicit memory allocation tracking is a lot less useful than one
might think, at least if what you are trying to do is to estimate how
much RAM your program is consuming. You will only get a very rough lower
limit, while the actual memory usage may be much larger (even
significantly larger in the worst cases).
==============================================================================
TOPIC: Global object initialization
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/4eccf55d938f3bf2?hl=en
==============================================================================
== 1 of 3 ==
Date: Tues, Sep 30 2008 7:27 am
From: Pete Becker
On 2008-09-30 09:02:29 -0400, Zeppe
<zep_p@remove.all.this.long.comment.yahoo.it> said:
> Pete Becker wrote:
>
>> In this example, that's true. But there's nothing special about main.
>
> There is, indeed.
Well, yes, main is in some ways special. But we were talking about
initialization, and the rule, once again, is that static objects must
be initialized before the first entry into any function defined in the
same translation unit. It doesn't matter whether the name of that
function is main, foo, bar, or billy. And it doesn't matter whether
main is also in that translation unit.
> And in particular, since main cannot be called explicitly, you are
> sure that the static variable is initialised before.
Again: that's true for every function, regardless of whether it can be
called explicitly.
> In addition, I'd say all the static variables from all the translation
> units are initialised before main() is called.
That's not required by the standard. The rule is as I've set out above.
That's a provision for dynamically linked libraries, which can be
loaded on demand, and don't initialize their statics until they are
loaded.
> What is undefined is the order of initialisation of static variables
> from different translation units.
That is unspecified, not undefined. But it's subject to the rule about
initizaliation before use of a function, as above.
> So, if g_a is used in a function foo that is called during the
> initialisation of a global variable in another translation unit, there
> can be problems.
Indeed.
>
> Usually in this cases a function returining a reference to the static
> variable can force a safe order of initialisation (even though by
> itself doesn't guarantee the initialisation before main).
>
> A g_a()
> {
> static A g_a;
> return g_a;
> }
>
That's one way to manage initialization order, but that's a separate
issue from the requirement about initialization before entry into a
function.
--
Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The
Standard C++ Library Extensions: a Tutorial and Reference
(www.petebecker.com/tr1book)
== 2 of 3 ==
Date: Tues, Sep 30 2008 8:37 am
From: Maxim Yegorushkin
On Sep 30, 11:44 am, Pete Becker <p...@versatilecoding.com> wrote:
> On 2008-09-30 04:07:55 -0400, asm23 <asmwarr...@gmail.com> said:
>
>
>
> > kirya...@gmail.com wrote:
> >> Hello. Given the code below does C++ Standard guarantee that the
> >> function my_init() will be called before main()?
>
> >> struct A
> >> {
> >> A()
> >> {
> >> my_init();
> >> }
> >> };
>
> >> A g_a;
>
> >> int main()
> >> {
> >> // ...
> >> }
> > Yes, a global variable will be initialized *before* main() entered. So,
> > the constructor of A will call my_init() before main().
>
> In this example, that's true. But there's nothing special about main.
> Global variables will be initialized before entry into any function
> defined in the same translation unit as the variable.
Please note, that there is nothing preventing a function to be called
before the global variables from the same translation unit are
initialised. For example, from a constructor of a global object from
another TU which happens to be initialised before the TU where the
function resides.
--
Max
== 3 of 3 ==
Date: Tues, Sep 30 2008 8:53 am
From: Pete Becker
On 2008-09-30 11:37:05 -0400, Maxim Yegorushkin
<maxim.yegorushkin@gmail.com> said:
>
> Please note, that there is nothing preventing a function to be called
> before the global variables from the same translation unit are
> initialised.
Now that I've looked it up, I see that I've overstated the rule. The
actual rule is that It's implementation-defined whether the
implementation does dynamic initialization before entry into main. If
it defers initialization, it must do dynamic initialization of objects
defined in a translation unit before the first use of any function or
object defined in the same translation unit. So in the typical case
where all the translation units are linked together and their statics
are initialized before entry into main, there is no requirement on the
relative order of dynamic initialization of objects defined in
different translation units.
--
Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The
Standard C++ Library Extensions: a Tutorial and Reference
(www.petebecker.com/tr1book)
==============================================================================
TOPIC: Trying to apply SFINAE
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/2d8ff4d0d6e8c793?hl=en
==============================================================================
== 1 of 1 ==
Date: Tues, Sep 30 2008 7:50 am
From: Victor Bazarov
Hendrik Schober wrote:
> Victor Bazarov wrote:
>> Hendrik Schober wrote:
>> [...]
>>
>> Well, the compiler cannot deduce the type from a default argument, I
>> vaguely recall that it's a non-deducible context. That's why putting
>> the traits there won't cut it. Consider
>>
>> #include <iterator>
>>
>> template<typename Iter>
>> void test(Iter, Iter, std::iterator_traits<Iter> const* = 0);
>>
>> int main ()
>> {
>> const int fa[] = { 1,2,3,4 };
>> test(fa, fa+4);
>> }
>
> Thanks! However, while the above works, this doesn't:
>
> #include <iterator>
>
> template< typename T >
> void test( T /*a1*/, T /*a2*/ ) {}
>
> template< typename Iter >
> void test( Iter /*b*/, Iter /*e*/
> , std::iterator_traits<Iter> = std::iterator_traits<Iter>()
> ) {}
>
> int main()
> {
> const int fa[] = { 255, 255, 255, 255 };
>
> test(0,1);
> test(fa, fa+4);
>
> return 0;
> }
>
> (Both VC and Comeau complain it's ambiguous.) But that's
> just what I need.
They are probably correct :-/
Let's try to involve a class where you can make a partial specialisation:
template<class T, bool> struct ActualWorker; // "abstract"
template<class T> struct ActualWorker<T,false> // non-iterator
{
static void test(T /*a1*/, T /*a2*/) { /*whatever*/ }
};
template<class T> class ActualWorker<T,true> // iterator
{
static void test(T /*i1*/, T /*i2*/) { /*whatever*/ }
};
// now - how do we determine it's an iterator?
template<class T> struct IsIterator { enum { yes = 0 }; };
template<class T> struct IsIterator {
... // here you need to add some way to set 'yes' to 1
... // if 'T' is an iterator. It's up to you to define
... // what is an iterator and what isn't.
};
template<class T> void test(T t1, T t2) {
return ActualWorker<T, IsIterator<T>::yes >::test(t1, t2);
}
int main()
{
test(42, 666);
int foo[] = { 1,2,3,4 };
test(foo, foo+4);
}
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
==============================================================================
TOPIC: How to make non-blocking call to cin?
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/0ab112b61c8dc29e?hl=en
==============================================================================
== 1 of 1 ==
Date: Tues, Sep 30 2008 8:36 am
From: ytrembla@nyx.nyx.net (Yannick Tremblay)
In article <gbssvu$dp7$2@south.jnrs.ja.net>, Lionel B <me@privacy.net> wrote:
>On Mon, 29 Sep 2008 15:18:56 +0000, Yannick Tremblay wrote:
>
>> In article
>> <f1ea726e-49a0-440b-bad9-1c8ca1637b11@a70g2000hsh.googlegroups.com>,
>> puzzlecracker <ironsel2000@gmail.com> wrote:
>>>is it even possible or/and there is a better alternative to accept input
>>>in a nonblocking manner?
>>
>> I'd avoid the problem altogether:
>>
>> I'd simply create a cin reader thread whose job would be to read input
>> safely from a blocking cin. It could also be charged with validating
>> this input if desirable.
>>
>> I'd put a thread safe FIFO communication mechanism between the two
>> threads (e.g. mutex protected std::queue) and the main process thread
>> would peek if there is a message on the queue for it, if so, read and
>> process it, if not, continue with its other tasks.
>>
>> To me, that sounds simpler than trying to turn cin as non-blocking. plus
>> anyway, non-blocking cin would think that there is data to be read if
>> only one character was present in the buffer but you may wish to get
>> input as complete words (lines?) and not interrupt normal processing
>> until a complete word is available. This would be trivial to do with
>> the input thread model but much more difficult with a non-blocking cin
>> or stdin.
>
>That sounds pretty complicated to me... but then I really don't know how
>you'd make cin non-blocking (or non-line-buffered, for that matter), so I
>don't know how complicated that would be.
Depends. I am fairly confortable with threads. Using boost threads,
creating a thread in a sane way is a couple of lines, a thread-safe
queue is obviously something that I have sitting in that library ready
to be used, so really not as complicated as it may sound.
It also make a nice separation of task:
Main thread does the processing
User input thread manage user input, read it and validate it before
passing it to the main thread.
Both threads have very limited interaction which is a good idea with
threads.
Each threads is individually simpler than if it was trying to do both
task in one.
Each thread can be independently tested.
Pattern very easy to extend to input via other channels than cin.
>But if you're prepared to forgo cin and use stdin, then (at least in
>unix) it's pretty straightforward - including getting line-buffered
>input in non-blocking mode. See e.g. my simple stdin control utilities
>and demo:
>
>ftp://ftp.informatics.sussex.ac.uk/pub/users/lionelb/misc/stdin_control
I had a peek at it. It's a nice little wrapper over fcntl. It would
probably be the better choice for simple task like non-blocking
character input.
Yannick
==============================================================================
TOPIC: What's the standard say about this code?
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/ba343bcb425e7e31?hl=en
==============================================================================
== 1 of 3 ==
Date: Tues, Sep 30 2008 8:40 am
From: "Daniel T."
#include <cassert>
class Foo {
public:
virtual void fnA() = 0;
virtual void fnB() = 0;
};
int main() {
assert( &Foo::fnB );
assert( &Foo::fnA );
}
What does the standard say about the above code? In the compiler I'm
using now, the first assert will not fire, but the second one will. I
expected that neither assert would fire...
== 2 of 3 ==
Date: Tues, Sep 30 2008 8:53 am
From: Maxim Yegorushkin
On Sep 30, 4:40 pm, "Daniel T." <danie...@earthlink.net> wrote:
> #include <cassert>
>
> class Foo {
> public:
> virtual void fnA() = 0;
> virtual void fnB() = 0;
>
> };
>
> int main() {
> assert( &Foo::fnB );
> assert( &Foo::fnA );
>
> }
>
> What does the standard say about the above code? In the compiler I'm
> using now, the first assert will not fire, but the second one will. I
> expected that neither assert would fire...
Are you sure that the second assert is failing?
Both &Foo::fnB and &Foo::fnA should yield a non-NULL member function
pointer, which gets converted to bool(true) when passed into assert().
--
Max
== 3 of 3 ==
Date: Tues, Sep 30 2008 9:21 am
From: "Daniel T."
On Sep 30, 11:53 am, Maxim Yegorushkin <maxim.yegorush...@gmail.com>
wrote:
> On Sep 30, 4:40 pm, "Daniel T." <danie...@earthlink.net> wrote:
>
>
>
> > #include <cassert>
>
> > class Foo {
> > public:
> > virtual void fnA() = 0;
> > virtual void fnB() = 0;
>
> > };
>
> > int main() {
> > assert( &Foo::fnB );
> > assert( &Foo::fnA );
>
> > }
>
> > What does the standard say about the above code? In the compiler I'm
> > using now, the first assert will not fire, but the second one will. I
> > expected that neither assert would fire...
>
> Are you sure that the second assert is failing?
>
> Both &Foo::fnB and &Foo::fnA should yield a non-NULL member function
> pointer, which gets converted to bool(true) when passed into assert().
Yes, I am sure that the second assert is failing. If this is a
compiler bug, then I will submit it to the vendor, but I want to make
sure it actually *is* a compiler bug first.
==============================================================================
TOPIC: passing object reference to the method
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/ce783dea61c7f4b8?hl=en
==============================================================================
== 1 of 3 ==
Date: Tues, Sep 30 2008 8:55 am
From: Pete Becker
On 2008-09-30 11:51:35 -0400, puzzlecracker <ironsel2000@gmail.com> said:
> Say I pass an object of a class (reference value I suppose) to a
> method, and I want to pass it by reference. Do I need to preappend
> it with ref.
>
> public interface IFoo{}
>
> public class Foo:IFoo{
>
> }
>
> void FromHere()
> {
>
> Foo f=new Foo();
> Here(ref f);
>
> }
>
> void Here(ref IFoo f )
> {
> //do something with f
> }
>
> Is ref redundant or error-prone. In my scenerio I have a lot of
> overload for Here-like function,
> and compiler screams that it cannot convert IFoo to char (latter
> beeing void Here(ref char c) )
>
This usage of ref is not part of standard C++. If a function takes an
argument by reference that argument is marked as a reference like this:
void Here(IFoo& f)
and it's called with the object:
Foo f;
Here(f);
Note that this is different from what the above code is doing, since
Foo f= new Foo() creates a pointer. I have no idea what the meaning of
those 'ref' decorations is.
--
Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The
Standard C++ Library Extensions: a Tutorial and Reference
(www.petebecker.com/tr1book)
== 2 of 3 ==
Date: Tues, Sep 30 2008 8:58 am
From: Obnoxious User
On Tue, 30 Sep 2008 08:51:35 -0700, puzzlecracker wrote:
> Say I pass an object of a class (reference value I suppose) to a method,
> and I want to pass it by reference. Do I need to preappend it with
> ref.
>
> public interface IFoo{}
>
> public class Foo:IFoo{
>
> }
>
> void FromHere()
> {
>
> Foo f=new Foo();
> Here(ref f);
>
> }
>
> void Here(ref IFoo f )
> {
> //do something with f
> }
>
> Is ref redundant or error-prone. In my scenerio I have a lot of
> overload for Here-like function,
> and compiler screams that it cannot convert IFoo to char (latter
> beeing void Here(ref char c) )
>
Are your sure this is C++? Most likely CLI/C++ or some
other Microsoft managed version.
--
OU
Remember 18th of June 2008, Democracy died that afternoon.
http://frapedia.se/wiki/Information_in_English
== 3 of 3 ==
Date: Tues, Sep 30 2008 10:29 am
From: puzzlecracker
On Sep 30, 11:58 am, Obnoxious User <O...@127.0.0.1> wrote:
> On Tue, 30 Sep 2008 08:51:35 -0700, puzzlecracker wrote:
> > Say I pass an object of a class (reference value I suppose) to a method,
> > and I want to pass it by reference. Do I need to preappend it with
> > ref.
>
> > public interface IFoo{}
>
> > public class Foo:IFoo{
>
> > }
>
> > void FromHere()
> > {
>
> > Foo f=new Foo();
> > Here(ref f);
>
> > }
>
> > void Here(ref IFoo f )
> > {
> > //do something with f
> > }
>
> > Is ref redundant or error-prone. In my scenerio I have a lot of
> > overload for Here-like function,
> > and compiler screams that it cannot convert IFoo to char (latter
> > beeing void Here(ref char c) )
>
> Are your sure this is C++? Most likely CLI/C++ or some
> other Microsoft managed version.
>
> --
> OU
> Remember 18th of June 2008, Democracy died that afternoon.http://frapedia.se/wiki/Information_in_English
Guys, It's csharp. I accidentally post this question here. It's now
reposted to the appropriate group.
==============================================================================
TOPIC: how to use libstdc++.so.5 instead of libstdc++.so.6
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/b79b9c199d58416b?hl=en
==============================================================================
== 1 of 1 ==
Date: Tues, Sep 30 2008 8:59 am
From: ytrembla@nyx.nyx.net (Yannick Tremblay)
This is off topic for this newsgroup. There are GNu newsgroups and Linux
development newsgroup where this would be more appropriate.
However, what you are trying to do is not quite simple nor totally reliable.
As you can see by the output of ldd, you have moved from .5 to .6 for
libstcdc++but the other libraries are also of a different version.
As an alternative, you could instead make a virtual machine on your dev
machine that is similar to the build machine. It might save you a lot of
hassle.
In article <6a70cf83-46e0-4605-ae88-62e5ac34a9dc@k13g2000hse.googlegroups.com>,
Alexander Dong Back Kim <alexdbkim@gmail.com> wrote:
>Dear all members,
>
>First of all, I apologize I posted such a topic which is not purely
>related with this group. The reason why I posted this is I hope some
>of members this group knows about g++ and they have better idea about
>my problem so please forgive my post.
>
>I have this problem that development machine's default C++ library is
>libstdc++.so.6. of course the OS is linux. However, the target machine
>has libstdc++.so.5 so I copied the library file to dev machine.
>
>Therefore, the dev machine has both version 5 and 6 of libstdc++
>whereas the target machine has only version 5. I wrote and tested the
>following application (not really an application) on the target
>machine.
>
>#include <iostream>
>using namespace std;
>int main() { cout << "hello" << endl; return 0; }
>
>I compile the code with...
>
>target $ g++ main.cpp
>
>It, of course, produces "a.out". I did "ldd" to see what shared (or
>dynamic) library the application links and the result was...
>
> libstdc++.so.5 => /usr/lib/libstdc++.so.5 (0x00c25000)
> libm.so.6 => /lib/tls/libm.so.6 (0x00951000)
> libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x006af000)
> libc.so.6 => /lib/tls/libc.so.6 (0x0026c000)
> /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x00a42000)
>
>Now I compiled the same application on the dev machine and did the
>same command and the result is...
>
> libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x005e8000)
> libm.so.6 => /lib/tls/libm.so.6 (0x00372000)
> libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x00555000)
> libc.so.6 => /lib/tls/libc.so.6 (0x0023e000)
> /lib/ld-linux.so.2 (0x00224000)
>
>If I run the application, which was compiled on the dev machine, on
>the target machine it says an error message...
>
>./a.out: error while loading shared libraries: libstdc++.so.6: cannot
>open shared object file: No such file or directory
>
>This totally makes sense because the target machine doesn't have the
>library "libstdc++.so.6". I did "ldd" and it shows more specific
>reason.
>
> libstdc++.so.6 => not found
> libm.so.6 => /lib/tls/libm.so.6 (0x0079b000)
> libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x00689000)
> libc.so.6 => /lib/tls/libc.so.6 (0x00111000)
> /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x0046c000)
>
>Now, I start falling in a panic because I have so many questions about
>next step. I simply thought I might be able to copy the lib file
>"libstdc++.so.6" from dev machine to target machine. However, I'm
>wornding whether this is right thing to do. Is this problem that
>simple? Would it cause some weird problems when a application needs to
>use such thing like RTTI or exception handling? Because of these many
>doubt, I slightly think about another way of doing this. What about
>using "libstdc++.so.5" when I compile the application on the dev
>machine?
>
>Now. How can I do this? I have no idea how I can force g++ choose
>libstdc++.so.5 instead of libstdc++.so.6? Moreover, I'm also worrying
>about whether it is right thing...
>
>or is whole my idea just crap? Please give me any suggestion or idea
>before I knock the door of hell...
>
>regards,
>Alex Kim
==============================================================================
TOPIC: C++ gurus, keywords: programming,search, expertise
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/c7f14464d8307503?hl=en
==============================================================================
== 1 of 1 ==
Date: Tues, Sep 30 2008 10:13 am
From: sasha
On Sep 29, 9:24 pm, red floyd <no.spam.h...@example.com> wrote:
> Andrey Hristoliubov wrote:
>
> [mostly redacted]
>
> FAQ 5.11 (http://www.parashift.com/c++-faq-lite/how-to-post.html#faq-5.11)
>
>
>
> and Bjarne Stroustrup (he asked me> for help to design C++ ; still unsure why he didn't give me enought
> > credit - probably a poor design choice to have Russian name near c+
> > +)
>
> And if my aunt had balls, she'd be my uncle.
This guy sent me his resume, awhile back, also looking for a job.
It's rather comical -- look at his latest experience. Absurd!
==============================================================================
TOPIC: ODR: A simple question
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/d65f12d76742875b?hl=en
==============================================================================
== 1 of 2 ==
Date: Tues, Sep 30 2008 10:58 am
From: ebony.soft@gmail.com
On Sep 29, 2:17 pm, Pete Becker <p...@versatilecoding.com> wrote:
> On 2008-09-29 06:01:07 -0400, ebony.s...@gmail.com said:
>
>
>
> > I encountered a simple but IMO important problem about the C++ linkage
> > model and One Definition Rule. Why the following code link?
>
> > file1.cpp
> > int x;
>
> > file2.cpp
> > double x;
>
> > x was defined in two different translation units with different types.
> > It breaks the ODR.
>
> The language definition doesn't require compilers to diagnose
> violations of the ODR. Code like this has undefined behavior. As a
> practical matter, recognizing errors like this is expensive, given
> C++'s separate compilation model.
>
> --
> Pete
> Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The
> Standard C++ Library Extensions: a Tutorial and Reference
> (www.petebecker.com/tr1book)
Sorry for a day delay. I was out of office.
Thank you pete for you answer, but I didn't completely convince.
I thought may be some standard conversions were made (double to int or
vice versa)
I changed double to std::string, but program run. Just when I declare
the variable
with extern, I have to specifiy the type and compiler find the real
type.
Which clause or section of C++ standard draft mention your answer?
Regards,
- Saeed Amrollahi
== 2 of 2 ==
Date: Tues, Sep 30 2008 11:06 am
From: ebony.soft@gmail.com
On Sep 29, 4:44 pm, James Kanze <james.ka...@gmail.com> wrote:
> On Sep 29, 1:17 pm, Pete Becker <p...@versatilecoding.com> wrote:
>
> > On 2008-09-29 06:01:07 -0400, ebony.s...@gmail.com said:
> > > I encountered a simple but IMO important problem about the
> > > C++ linkage model and One Definition Rule. Why the following
> > > code link?
> > > file1.cpp
> > > int x;
> > > file2.cpp
> > > double x;
> > > x was defined in two different translation units with
> > > different types. It breaks the ODR.
> > The language definition doesn't require compilers to diagnose
> > violations of the ODR. Code like this has undefined behavior. As a
> > practical matter, recognizing errors like this is expensive, given
> > C++'s separate compilation model.
>
> And the relatively low quality of most linkers. It wouldn't be
> very hard to implement, if the linker supported it. For
> historical reasons, most linkers don't.
>
> --
> James Kanze (GABI Software) email:james.ka...@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
Sorry for a day delay. I was out of office.
Thank you for your answer. AFAIR, Stroustrup mentioned the poor
quality of linkers in 1st edition
of his book. Where can I find, C++ Linker specific information?
Regards,
Saeed Amrollahi
==============================================================================
TOPIC: (&vec)== &vec[0]?
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/d77c87f0acfdcd75?hl=en
==============================================================================
== 1 of 1 ==
Date: Tues, Sep 30 2008 11:14 am
From: Ioannis Vranos
C++03:
Is it always guaranteed that in vector:
vector<int> vec(10);
&vec always points to the first element of the array, for vec.size()> 0?
==============================================================================
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