3

What are 'aliased stream buffers`? I encountered the term in a comment on an answer of mine.

Community
  • 1
  • 1
xtofl
  • 38,207
  • 10
  • 95
  • 177

3 Answers3

3

I've never heard the term before, but in the thread you cite, the person who used it also gave an example: two streams which use the same streambuf.

Of course, just because two streams don't use the same streambuf, doesn't mean that data written to them doesn't ultimately end up in the same place; that they don't alias the same sink, if that is what is meant. There are filtering streambuf's, which forward the actual sinking and sourcing to another streambuf, and on most systems, it's possible to open a file at the system level, and connect a streambuf (or two) to it.

-- James Kanze

xtofl
  • 38,207
  • 10
  • 95
  • 177
James Kanze
  • 142,482
  • 15
  • 169
  • 310
  • +1 for explaining my term :) I used the term aliasing because it is akin to the concept of pointer aliasing – sehe Mar 14 '11 at 12:30
1

It means an object with different name, for example this:

ostream &lbw = cout;

lbw << "Shahid out" << "Sachin in" << endl; //goes to cout!
Nawaz
  • 327,095
  • 105
  • 629
  • 812
  • that's it? it's just a different name for a reference? – Naveen Mar 14 '11 at 09:03
  • that makes stdout anti aliased – stefan Mar 14 '11 at 09:05
  • @Naveen: Did I miss anything? Please correct me if I'm wrong. :-) – Nawaz Mar 14 '11 at 09:05
  • @Nawaz: I don't the answer, I was expecting bit more complicated than that :) I was suprised to see this. – Naveen Mar 14 '11 at 09:07
  • @Naveen: Ohh... In C++, you can have a [short alias](http://www.ideone.com/DLZ6t) of a very very long namespace, but when it comes to object, it's a reference which is sometimes called alias! – Nawaz Mar 14 '11 at 09:15
  • @Naveen, @Nawaz: I meant rdbuf sharing as aptly explained by others. References are just references. Pointers are just pointers. Pointers or reference are usually said to alias when they refer to (part of) the same memory location, within the same context that might make assumptions on identity and uniqueness of such references(otherwise, it is just another variable with the same value). – sehe Mar 14 '11 at 12:38
1

What probably was meant in the comment there is this:

ofstream file;
file.rdbuf(cout.rdbuf());

// writes to cout
file << "hello";

So now the check there doesn't work:

if(&file == &cout)
    // no, it doesn't
Yakov Galka
  • 61,035
  • 13
  • 128
  • 192