Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

what is an escaping variable

32 views
Skip to first unread message

C C++ C++

unread,
Nov 12, 2007, 10:46:43 AM11/12/07
to
what is an escaping variable?

Victor Bazarov

unread,
Nov 12, 2007, 10:50:05 AM11/12/07
to
C C++ C++ wrote:
> what is an escaping variable?

A variable the control over whom you're losing?

I don't know of "escaping variable", but there is "escape sequence"
in formatted output...

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask


Roland Pibinger

unread,
Nov 12, 2007, 4:56:49 PM11/12/07
to
On Mon, 12 Nov 2007 15:46:43 -0000, C C++ C++ <m.azmath@...com> wrote:
>what is an escaping variable?

A variable that escapes a function?
http://en.wikipedia.org/wiki/Escape_analysis
BTW, scope bound resource management using RAII is a panacea for
avoiding escaping variables.


--
Roland Pibinger
"The best software is simple, elegant, and full of drama" - Grady Booch

Kira Yamato

unread,
Nov 12, 2007, 5:01:35 PM11/12/07
to
On 2007-11-12 16:56:49 -0500, rpb...@yahoo.com (Roland Pibinger) said:

> On Mon, 12 Nov 2007 15:46:43 -0000, C C++ C++ <m.azmath@...com> wrote:
>> what is an escaping variable?
>
> A variable that escapes a function?
> http://en.wikipedia.org/wiki/Escape_analysis
> BTW, scope bound resource management using RAII is a panacea for
> avoiding escaping variables.

Can you give an example?

--

-kira

Roland Pibinger

unread,
Nov 12, 2007, 5:53:53 PM11/12/07
to

An example of 'escaping' variables or RAII?

Kira Yamato

unread,
Nov 12, 2007, 6:09:28 PM11/12/07
to

Escaping variable. I just want to see what that code would like.

And perhaps if someone has time, show me what this RAII is and how it
avoids escape variables. But I sense that would be asking for too much.

--

-kira

Roland Pibinger

unread,
Nov 12, 2007, 7:02:21 PM11/12/07
to
On Mon, 12 Nov 2007 18:09:28 -0500, Kira Yamato wrote:
>On 2007-11-12 17:53:53 -0500, rpb...@yahoo.com (Roland Pibinger) said:
>> On Mon, 12 Nov 2007 Kira Yamato wrote:
>>> Can you give an example?
>>
>> An example of 'escaping' variables or RAII?
>
>Escaping variable. I just want to see what that code would like.
>
>And perhaps if someone has time, show me what this RAII is and how it
>avoids escape variables. But I sense that would be asking for too much.

From Wikipedia:
"If a subroutine allocates an object and returns a pointer to it, the
object can be accessed from undetermined places in the program — the
pointer has 'escaped'."

MyClass* foo() {
return new MyClass;
}

Escaping has 2 consequences in C++
1. The caller must clean-up (delete) the resource which is impractical
for larger applications.
2. The caller becomes (probably) dependent on MyClass an all types
MyClass depends on (and so forth).

RAII is described here: http://en.wikipedia.org/wiki/RAII .
When you make the desctuctor of the managing object private (as shown
in the RAII example) the managed objects cannot escape from the
enclosing scope.

Roland Pibinger

unread,
Nov 12, 2007, 7:09:13 PM11/12/07
to
On Tue, 13 Nov 2007 00:02:21 GMT, Roland Pibinger wrote:

>When you make the desctuctor of the managing object private (as shown
>in the RAII example) the managed objects cannot escape from the
>enclosing scope.

Should have been: "When you make the copy constructor of the managing
object private ...". Sorry.

Raz

unread,
May 5, 2008, 7:23:50 PM5/5/08
to

On Wed, 30 Apr 2008 21:54:37 GMT, Erik Wikströ

>Obviously his knowledge of C++ is not as good as it should be.

As I said, I will find the link again. His knowledge of C++ is just
fine.

http://www.builderau.com.au/video/soa/Rusty-s-message-to-C-programmers/0,2000064338,22432924p,00.htm

http://www.builderau.com.au/video/soa/Why-C-remains-relevant/0,2000064338,22432921p,00.htm

So here is an expert of who believes that you don't need C++ to
program low level. C++ brings extra complexity that is not needed. C
is #1 language to program in lower level. We can also add that you
don't need C++ to program in higher level either, as you can use
easier and better languages such as C#, Java, Ruby on Ralis, Perl,
Python.

Ian Collins

unread,
May 5, 2008, 6:27:14 PM5/5/08
to
Raz wrote:

Please confine your trolling to where it belongs.

--
Ian Collins.

Chris Thomasson

unread,
May 5, 2008, 6:46:18 PM5/5/08
to
"Raz" <os...@gmail.com> wrote in message
news:715v141f46a5eg638...@4ax.com...

>
> On Wed, 30 Apr 2008 21:54:37 GMT, Erik Wikströ
>
>>Obviously his knowledge of C++ is not as good as it should be.
>
> As I said, I will find the link again. His knowledge of C++ is just
> fine.
>
> http://www.builderau.com.au/video/soa/Rusty-s-message-to-C-programmers/0,2000064338,22432924p,00.htm
>
> http://www.builderau.com.au/video/soa/Why-C-remains-relevant/0,2000064338,22432921p,00.htm
>
> So here is an expert of who believes that you don't need C++ to
> program low level. C++ brings extra complexity that is not needed.

[...]

You are not forced to use "all" the features of C++. One could most
certainly use C++ in a kernel. However, I personally would avoid exceptions
and global ctor/dtors like the plague. I also would not use the STL, oh
well...

Razi

unread,
May 5, 2008, 7:52:48 PM5/5/08
to
On Tue, 06 May 2008 10:27:14 +1200, Ian Collins <ian-...@hotmail.com>
wrote:

>Please confine your trolling to where it belongs.

Earlier you claimed I didn't post the sources. Now proof has been
posted, and it's the opinion of experts that you don't need C++ to
program in lower level since C++ just brings extra complexity. C has
always been way ahead of C++ in popularity and usage anyway, all
throughout years. That itself is a solid proof. C++ never did replace
C.

In any case, what makes you guys respond to each of my posts with
one-liner "troll" and "plonk" when you think I am troll? I find it
hilarious, really. I never respond to a troll with a post "troll"
like a bot repeatedly. That's breaking #1 rule of how to deal with a
troll. Could it be that C++ has caused you guys to lose some brain
chips and behave in deranged ways? That's a possibility that can't be
discounted. Perhaps we should a new thread to discuss that topic?

Peter Duniho

unread,
May 5, 2008, 7:40:04 PM5/5/08
to
On Mon, 05 May 2008 16:52:48 -0700, <"Razi<lsdop"@gmail.com>> wrote:

> [...]


> In any case, what makes you guys respond to each of my posts with
> one-liner "troll" and "plonk" when you think I am troll?

To emphasize to others that you ARE a troll. The replies aren't for your
benefit. If anything, you make our lives easier when you "plonk" us,
because we can then post messages knowing that there's no chance you'll
actually reply to them.

I see that, having found the C++ and Java newsgroups more and more
resistant to your trolling, you've now started including the C newsgroup.
Fortunately, the more unrelated newsgroups you insist on including in your
posts, the more obvious it is that you're trolling. I'm hopeful that
those in the C newsgroup will more readily realize that you're trolling
and skip the annoying phase of trying to reply seriously only to find out
that serious replies don't have any effect on you.

Of course, the fact that this latest thread has zero to do with Java
programming also helps make it more obvious that you're just trolling.
Again, your greed will eventually be your own undoing. Then you'll be
free of your trolling obligations and will be able to go get a life. When
that finally happens, everyone will live happily ever after, yourself
included. Who could ask for a better fairy tale ending? :)

Pete

CBFalconer

unread,
May 5, 2008, 8:19:18 PM5/5/08
to

Do you realize that you are posting to comp.lang.c, and that your
posts are off-topic there? Simply delete c.l.c from the
distribution.

And try not to change your name etc. between postings.

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.


** Posted from http://www.teranews.com **

Razii

unread,
May 5, 2008, 11:23:39 PM5/5/08
to
On Mon, 05 May 2008 20:19:18 -0400, CBFalconer <cbfal...@yahoo.com>
wrote:

>Do you realize that you are posting to comp.lang.c, and that your
>posts are off-topic there? Simply delete c.l.c from the
>distribution.

From now on, all my posts would bee cross posted to comp.lang.c. What
are you going to do about it? Whine a little more?


Razii

unread,
May 5, 2008, 11:34:43 PM5/5/08
to
On Mon, 05 May 2008 16:40:04 -0700, "Peter Duniho"
<NpOeS...@nnowslpianmk.com> wrote:

>Fortunately, the more unrelated newsgroups you insist on including in your
>posts, the more obvious it is that you're trolling.

I really don't care if people respond to me. I am going to continue
with shootout game for MY OWN pleasure. You are free to ignore it,
whine, and post whatever flame. Of course posting it here makes it
more fun since for some reason, all my threads generate a lot of
responses :) even whining, like you do, is counted as a response.
Did you know that?

Since someone whined from C newsgroup, from now on I will add that
group to the list of my posts. That group is relevant to topic as far
as I am concerned. We are doing benchmark of different language
implementation, so all languages, including C, is relevant to the
discussion.


CBFalconer

unread,
May 5, 2008, 10:57:19 PM5/5/08
to
Razii wrote:
> CBFalconer <cbfal...@yahoo.com> wrote:
>
>> Do you realize that you are posting to comp.lang.c, and that your
>> posts are off-topic there? Simply delete c.l.c from the
>> distribution.
>
> From now on, all my posts would bee cross posted to comp.lang.c.
> What are you going to do about it? Whine a little more?

PLONK. Bye now.

Mike Schilling

unread,
May 5, 2008, 11:51:12 PM5/5/08
to

As suggested in your post's headers, I'm going to forward this to
ab...@rr.com . I encourage the rest of you to join me.


Razi

unread,
May 6, 2008, 1:29:59 AM5/6/08
to
On Mon, 5 May 2008 20:51:12 -0700, "Mike Schilling"
<mscotts...@hotmail.com> wrote:

>As suggested in your post's headers, I'm going to forward this to
>ab...@rr.com . I encourage the rest of you to join me.

And now I am using aioe.org .. their email is probably,
ab...@aioe.org , in case you need help.

I can continue with next server in the next post if you want me to,
for at least two dozen servers continuously. After that, there is all
too reliable google.

Good luck in your email adventure anyway. There is nothing abusive
about posting benchmarks related to Java, C and C++ on a USENET
newsgroup.

Chris Thomasson

unread,
May 6, 2008, 2:36:50 AM5/6/08
to
"Mike Schilling" <mscotts...@hotmail.com> wrote in message
news:RAQTj.8626$iK6....@nlpi069.nbdc.sbc.com...

What I was trying to tell Razii all along is that one can spend about 10-15
minutes creating a _very_ crude general purpose memory allocator in C++ that
can at least "compete" with Java:

http://groups.google.com/group/comp.lang.c++/browse_frm/thread/68bdc76f9792de1f


JET aside for a moment, one must remember that Java has advantage of using
many tricks in the initial byte-code compilation and/or subsequent JIT
process. Its nice to now that many popular JVM's are still written in C
and/or C++; I am not going to plonk him just yet...

:^/

cr88192

unread,
May 6, 2008, 2:06:07 AM5/6/08
to

"Chris Thomasson" <cri...@comcast.net> wrote in message
news:_eadnWL1xbc8EILV...@comcast.com...

one has to give up many of the features, and is still faced with many of the
other technical issues, that IMO one is better off just using C...

Mike Schilling

unread,
May 6, 2008, 2:37:03 AM5/6/08
to
Razi wrote:
> On Mon, 5 May 2008 20:51:12 -0700, "Mike Schilling"
> <mscotts...@hotmail.com> wrote:
>
>> As suggested in your post's headers, I'm going to forward this to
>> ab...@rr.com . I encourage the rest of you to join me.
>
> And now I am using aioe.org .. their email is probably,
> ab...@aioe.org , in case you need help.
>
> I can continue with next server in the next post if you want me to,
> for at least two dozen servers continuously. After that, there is
> all
> too reliable google.

Why do you need to switch servers so often, if you're not a spammer?


Chris Thomasson

unread,
May 6, 2008, 3:06:17 AM5/6/08
to
"cr88192" <cr8...@NOSPAM.hotmail.com> wrote in message
news:51475$481ff7ff$ca83b482$34...@saipan.com...

Use all POD's, no ctor/dtor/"AUTO-vtable":

struct [kobject_name_POD] {
[state];

void ctor() {
}

void dtor() throw() {
}

[kobject_name_POD_API];
};


Think in terms of:


http://groups.google.com/group/comp.lang.c/browse_frm/thread/1b106926ba5db19f

convert that C code into simple C++ interface... POD and ASM can be used in
a Kernel.


Use only explicit C++ POD, __NO__ STL, exceptions, constructor, destructors,
virtual functions, inheritance, whatever... Every object is POD; ctor/dtor
is explicit. POD templates would be allowed. You can still benefit from the
syntax of the language - kernel unfriendly features.

Each POD can be initalized like:

struct Kernel_atomic_word {
atomic_word m_value;


#define KERNEL_ATOMIC_WORD_STATICINIT(mp_value) { \
(mp_value) \
}


void ctor(atomic_word const value) {
m_value = value;
}


void dtor() throw() {}


// fetch-and-add
atomic_word faa_mbacq(atomic_word const addend) throw() {
atomic_word const result = ATOMIC_FAA(&m_value, addend);
MEMBAR_ACQUIRE();
return result;
}

atomic_word faa_mbrel(atomic_word const addend) throw() {
MEMBAR_RELEASE();
return ATOMIC_FAA(&m_value, addend);
}


// swap
atomic_word swp_mbacq(atomic_word const value) throw() {
atomic_word const result = ATOMIC_SWP(&m_value, addend);
MEMBAR_ACQUIRE();
return result;
}

atomic_word swp_mbrel(atomic_word const value) throw() {
MEMBAR_RELEASE();
return ATOMIC_SWP(&m_value, addend);
}
};

Of course, C is nice... See, you can do "crude" OOP in C:'

http://groups.google.com/group/comp.lang.c/browse_frm/thread/1b106926ba5db19f


;^)


Humm, well, it every abstract interface has a vtable, yet their all POD...
Humm... Could possibly useful in a Kernel environment.

Indeed...

One can use C/C++ syntax in
(POD+someASM+OOP)-(exceptions+ctor/dtor+virtual_func) in a Kernel...

Chris Thomasson

unread,
May 6, 2008, 3:07:34 AM5/6/08
to
"Chris Thomasson" <cri...@comcast.net> wrote in message
news:34idnS8osed0ZoLV...@comcast.com...

> "Mike Schilling" <mscotts...@hotmail.com> wrote in message
> news:RAQTj.8626$iK6....@nlpi069.nbdc.sbc.com...
>> Razii wrote:
>>> On Mon, 05 May 2008 20:19:18 -0400, CBFalconer <cbfal...@yahoo.com>
>>> wrote:
>>>
>>>> Do you realize that you are posting to comp.lang.c, and that your
>>>> posts are off-topic there? Simply delete c.l.c from the
>>>> distribution.
>>>
>>> From now on, all my posts would bee cross posted to comp.lang.c. What
>>> are you going to do about it?
>>
>> As suggested in your post's headers, I'm going to forward this to
>> ab...@rr.com . I encourage the rest of you to join me.
>
> What I was trying to tell Razii all along is that one can spend about
> 10-15 minutes creating a _very_ crude general purpose memory allocator in
> C++ that can at least "compete" with Java:
>
> http://groups.google.com/group/comp.lang.c++/browse_frm/thread/68bdc76f9792de1f

[...]

Oh yeah, region allocator in C is simple:

http://groups.google.com/group/comp.lang.c/browse_frm/thread/f8f65273b09b4229

Ian Collins

unread,
May 6, 2008, 3:13:05 AM5/6/08
to
Chris Thomasson wrote:
> "cr88192" <cr8...@NOSPAM.hotmail.com> wrote in message
> news:51475$481ff7ff$ca83b482$34...@saipan.com...
>>
>> "Chris Thomasson" <cri...@comcast.net> wrote in message
>> news:_eadnWL1xbc8EILV...@comcast.com...
>>> "Raz" <os...@gmail.com> wrote in message
>>> news:715v141f46a5eg638...@4ax.com...
>>>>
>>>> On Wed, 30 Apr 2008 21:54:37 GMT, Erik Wikströ
>>>>
>>>>> Obviously his knowledge of C++ is not as good as it should be.
>>>>
>>>> As I said, I will find the link again. His knowledge of C++ is just
>>>> fine.
>>>>
>>>> http://www.builderau.com.au/video/soa/Rusty-s-message-to-C-programmers/0,2000064338,22432924p,00.htm
>>>>
>>>>
>>>> http://www.builderau.com.au/video/soa/Why-C-remains-relevant/0,2000064338,22432921p,00.htm
>>>>
>>>>
>>>> So here is an expert of who believes that you don't need C++ to
>>>> program low level. C++ brings extra complexity that is not needed.
>>>
>>> [...]
>>>
>>> You are not forced to use "all" the features of C++. One could most
>>> certainly use C++ in a kernel. However, I personally would avoid
>>> exceptions and global ctor/dtors like the plague. I also would not
>>> use the STL, oh well...
>>
>> one has to give up many of the features, and is still faced with many
>> of the other technical issues, that IMO one is better off just using C...
>
> Use all POD's, no ctor/dtor/"AUTO-vtable":
>
Why omit constructors and destructors?

--
Ian Collins.

Razii

unread,
May 6, 2008, 4:34:45 AM5/6/08
to
On Mon, 5 May 2008 23:37:03 -0700, "Mike Schilling"
<mscotts...@hotmail.com> wrote:

>Why do you need to switch servers so often, if you're not a spammer?

I switched servers to make a point. There are thousands of usenet
servers. Some free and many commercial specialized servers. Many of
them will never cancel an account because of the kind of posts I am
postings. Do you know how many zillion of pirated movies, songs, and
software is posted to the usenet? If these commercial servers don't
cancel accounts because their customers are breaking the law, why do
you think they will cancel accounts because I am posting benchmarks to
f*cking usenet newsgroups?

These groups are filled with porn. Don't you find it strange that
someone like CBFalconer wades through all the spam, finds my thread,
and starts lecturing and/or insulting me? He could have just moved on
to the next thread, as he did by ignoring zillion of spam. He could
have just filtered the thread and added me to ignore list. But no, he
had to lecture and then post one-liner "Plonk." Why he did that?
Because he is an abusive troll.

But that's fine. If you want to be abusive troll, that's all right.
Doesn't bother me. I will return the favor if/when I can.


Keith Thompson

unread,
May 6, 2008, 3:55:40 AM5/6/08
to
Razii <hj...@gmail.com> writes:
> On Mon, 5 May 2008 23:37:03 -0700, "Mike Schilling"
> <mscotts...@hotmail.com> wrote:
>
>>Why do you need to switch servers so often, if you're not a spammer?
>
> I switched servers to make a point.
[snip]

Ok, you've made your point. You can post anything you like to
unmoderated newsgroups, and nobody can stop you.

We already knew that.

--
Keith Thompson (The_Other_Keith) ks...@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"

santosh

unread,
May 6, 2008, 4:55:45 AM5/6/08
to
Keith Thompson wrote:

> Razii <hj...@gmail.com> writes:
>> On Mon, 5 May 2008 23:37:03 -0700, "Mike Schilling"
>> <mscotts...@hotmail.com> wrote:
>>
>>>Why do you need to switch servers so often, if you're not a spammer?
>>
>> I switched servers to make a point.
> [snip]
>
> Ok, you've made your point. You can post anything you like to
> unmoderated newsgroups, and nobody can stop you.
>
> We already knew that.

Well, the news servers *can* stop him. A tiny little filter is all that
it takes, to be updated whenever he switches identity. But frankly,
end-user killfilling is better for small-time annoyances like him.

dizzy

unread,
May 6, 2008, 5:38:52 AM5/6/08
to
cr88192 wrote:

> one has to give up many of the features, and is still faced with many of
> the other technical issues, that IMO one is better off just using C...

I completely agree. Once you start dropping features from C++ (templates,
exceptions, RAII, references, function and operator overloading) then you
get an incomplete language, some sort of "C with classes" (the horror!) so
you should better use C then.

I feel so lucky that I don't have to drop any C++ feature...

--
Dizzy

Ian Collins

unread,
May 6, 2008, 5:49:37 AM5/6/08
to
dizzy wrote:
> cr88192 wrote:
>
>> one has to give up many of the features, and is still faced with many of
>> the other technical issues, that IMO one is better off just using C...
>
> I completely agree. Once you start dropping features from C++ (templates,
> exceptions, RAII, references, function and operator overloading) then you
> get an incomplete language, some sort of "C with classes" (the horror!) so
> you should better use C then.
>
Why would you have to drop templates, RAII, references, function and
operator overloading in driver code? Exceptions typically require some
form of run time support, but none of the other language features you
mention do.

--
Ian Collins.

Joe Greer

unread,
May 6, 2008, 8:52:22 AM5/6/08
to
Ian Collins <ian-...@hotmail.com> wrote in
news:68antgF2...@mid.individual.net:

I don't know that you would have to drop them as a matter of course,
because you can actually get better performance with templates than
without. The problem comes when you want secure code. Templates have this
problem with doing different things depending upon the arguments and
parameters they are instantiated with. This makes them hard to reason
about and know exactly what is going to be generated. In secure contexts
this is enough of a problem that they are often banned entirely. I would
be interested in hearing if there are other arguments against templates.
Personally, I would think that your more algarithmic templates would be ok,
but as soon as you start doing metaprogramming with specializations etc,
then I would be more hesitant.

joe

Joe Greer

unread,
May 6, 2008, 9:02:33 AM5/6/08
to
Ian Collins <ian-...@hotmail.com> wrote in
news:68aeo1F...@mid.individual.net:

> Why omit constructors and destructors?
>

I would be interested in the answer to this myself. I know that in real
time systems they don't want the somewhat uncontrolled flurry of activity
that usually accompanies a method exit, however most OS's aren't real time
and I wouldn't think that it would matter in the main. Of course, you
can't really have dynamically allocated objects. You end up with a chicken
an egg problem there. That is, you can't use the memory subsystem to
implement the memory subsystem and all that. However, I personally create
a whole lot more stack objects than heap objects and that wouldn't be a
reason to ban objects entirely.


joe

ma...@pulsesoft.com

unread,
May 6, 2008, 10:21:43 AM5/6/08
to
Ian Collins <ian-...@hotmail.com> writes:

Some of that is addressed here:
http://www.microsoft.com/whdc/driver/kernel/KMcode.mspx

brad

unread,
May 6, 2008, 10:38:20 AM5/6/08
to
Raz wrote:

> So here is an expert of who believes that you don't need C++ to
> program low level. C++ brings extra complexity that is not needed. C
> is #1 language to program in lower level. We can also add that you
> don't need C++ to program in higher level either, as you can use
> easier and better languages such as C#, Java, Ruby on Ralis, Perl,
> Python.

I chose to learn C++ because of the options it provides... the
complexity that you refer to. I can do old-fashioned C, OOP, sequential,
functional, etc. I can do char arrays or use strings. I'm proficient in
Python and Ruby and I like them very much, but there are times when I
need native, compiled code for performance and efficiency reasons...
when that happens I normally use C++ in a C like manner. C++ does not
force me into a certain programming paradigm. That's what I like most
about it. I don't think it is a better C, IMO it's C with more
options... use them if you like, but you don't have to... and if you do
not need the additional options, then just stick with C. They are so
similar that it's not really worth arguing about.

Just my 2 cents,

Brad

Erik Wikström

unread,
May 6, 2008, 11:56:39 AM5/6/08
to
On 2008-05-06 09:06, Chris Thomasson wrote:

> Use only explicit C++ POD, __NO__ STL, exceptions, constructor, destructors,
> virtual functions, inheritance, whatever... Every object is POD; ctor/dtor
> is explicit. POD templates would be allowed. You can still benefit from the
> syntax of the language - kernel unfriendly features.

Why limit yourself to PODs? Constructors and destructors can be useful
even in a kernel environment (probably the constructors more than the
destructors though). Virtual functions are also useful, in fact they are
used all over modern kernels (but implemented using function-pointers).
Inheritance can also be useful, I've seen some code like this:

struct Base {
uint16_t type;
};

struct Some_thing {
uint16_t type;
// more data
};

And then you cast Some_thing* to Base* and pass them around and use the
type-field to cast them back, you might just as well use inheritance and
make the connection between the classes explicit in the code.

Of course you can not use every feature (I would not use exceptions or
STL and some other stuff) and you have to be smart about those you use,
but I think that most of the new stuff can find a place in a kernel.


PS: Groups other than c.l.c++ removed.

--
Erik Wikström

Ian Collins

unread,
May 6, 2008, 3:33:04 PM5/6/08
to
ma...@pulsesoft.com wrote:
> Ian Collins <ian-...@hotmail.com> writes:
>
>> dizzy wrote:
>>> cr88192 wrote:
>>>
>>>> one has to give up many of the features, and is still faced with many of
>>>> the other technical issues, that IMO one is better off just using C...
>>> I completely agree. Once you start dropping features from C++ (templates,
>>> exceptions, RAII, references, function and operator overloading) then you
>>> get an incomplete language, some sort of "C with classes" (the horror!) so
>>> you should better use C then.
>>>
>> Why would you have to drop templates, RAII, references, function and
>> operator overloading in driver code? Exceptions typically require some
>> form of run time support, but none of the other language features you
>> mention do.
>>
>

For one compiler. I haven't experienced the problems they cite with
embedded compilers, or with my main hosted compiler.

--
Ian Collins.

ma...@pulsesoft.com

unread,
May 6, 2008, 5:11:40 PM5/6/08
to
Ian Collins <ian-...@hotmail.com> writes:

Ergo the problems do not exist? That's wishful thinking.

--
mailto:av1...@comtv.ru

Ian Collins

unread,
May 6, 2008, 5:16:03 PM5/6/08
to
Not if you use the right tool for the job.

--
Ian Collins.

peter koch

unread,
May 6, 2008, 5:30:37 PM5/6/08
to
On 6 Maj, 23:11, m...@pulsesoft.com wrote:
> Ian Collins <ian-n...@hotmail.com> writes:
> > m...@pulsesoft.com wrote:

> >> Ian Collins <ian-n...@hotmail.com> writes:
>
> >>> dizzy wrote:
> >>>> cr88192 wrote:
>
> >>>>> one has to give up many of the features, and is still faced with many of
> >>>>> the other technical issues, that IMO one is better off just using C...
> >>>> I completely agree. Once you start dropping features from C++ (templates,
> >>>> exceptions, RAII, references, function and operator overloading) then you
> >>>> get an incomplete language, some sort of "C with classes" (the horror!) so
> >>>> you should better use C then.
>
> >>> Why would you have to drop templates, RAII, references, function and
> >>> operator overloading in driver code?  Exceptions typically require some
> >>> form of run time support, but none of the other language features you
> >>> mention do.
>
> >> Some of that is addressed here:
> >>http://www.microsoft.com/whdc/driver/kernel/KMcode.mspx
>
> > For one compiler.  I haven't experienced the problems they cite with
> > embedded compilers, or with my main hosted compiler.
>
> Ergo the problems do not exist? That's wishful thinking.
The Microsoft compiler is notoriously bad wrt its exception handling,
which from logical point of view shouldnt need any OS support. The
problem is that MS thought it wise to include operating system
exceptions (such as divide by zero or dereferencing of an invalid
pointer) as a part of the exception handling machinery.
There's no way back from that decision: we will have to 64-bit windows
to repair this. This also means that C++ will be a very poor choice
for 32-bit kernel/OS development unless you cut at least exceptions
out of the game.

/Peter

Mike Schilling

unread,
May 7, 2008, 1:26:48 AM5/7/08
to
brad wrote:
>
> I chose to learn C++ because of the options it provides... the
> complexity that you refer to. I can do old-fashioned C, OOP,
> sequential, functional, etc. I can do char arrays or use strings.
> I'm
> proficient in Python and Ruby and I like them very much, but there
> are times when I need native, compiled code for performance and
> efficiency reasons... when that happens I normally use C++ in a C
> like manner. C++ does not force me into a certain programming
> paradigm. That's what I like most about it. I don't think it is a
> better C, IMO it's C with more options... use them if you like, but
> you don't have to... and if you do not need the additional options,
> then just stick with C. They are so similar that it's not really
> worth arguing about.

Note that function prototypes, which were a significant hole in C's
strong typing [1], originated with C++.

Hypothetically, if I were going to program in C++-like C, I'd still
use classes to provide data-hiding and encapsulation, but I'd do
without (at least)

* operator overloading
* virtual functions
* virtual base classes
* templates

Am I leaving anything out?

1. This isn't just a theoretical opinion. I used to work on a very
large suite of C applications, and invalid parameter types were a
common source of errors, particularly where they were "close enough"
on the platform we were developing on, but not on some of the ones we
ported to.


Razii

unread,
May 7, 2008, 3:01:21 AM5/7/08
to
On Tue, 06 May 2008 00:55:40 -0700, Keith Thompson <ks...@mib.org>
wrote:

>We already knew that.

Who is "We"? I wasn't talking to you. The person I responded to didn't
know that.

dizzy

unread,
May 7, 2008, 4:17:07 AM5/7/08
to
Ian Collins wrote:

> dizzy wrote:
>> cr88192 wrote:
>>
>>> one has to give up many of the features, and is still faced with many of
>>> the other technical issues, that IMO one is better off just using C...
>>
>> I completely agree. Once you start dropping features from C++ (templates,
>> exceptions, RAII, references, function and operator overloading) then you
>> get an incomplete language, some sort of "C with classes" (the horror!)
>> so you should better use C then.
>>
> Why would you have to drop templates, RAII, references, function and
> operator overloading in driver code?

I wouldn't, especially RAII (I still have fantasies of using RAII for scoped
locking, resource management together with some auto_ptr-like move
semantics in the linux kernel code).

> Exceptions typically require some
> form of run time support, but none of the other language features you
> mention do.

I see. I supose it also has to do with code being more explicit with other
exception handling than C++ exceptions (but also bloated, adding noise to
the source, polluting the source with error handling paths).

--
Dizzy

James Kanze

unread,
May 7, 2008, 5:33:20 AM5/7/08
to
On May 6, 12:46 am, "Chris Thomasson" <cris...@comcast.net> wrote:
> "Raz" <os...@gmail.com> wrote in message
> news:715v141f46a5eg638...@4ax.com...
> > On Wed, 30 Apr 2008 21:54:37 GMT, Erik Wikströ

> >>Obviously his knowledge of C++ is not as good as it should be.

> > As I said, I will find the link again. His knowledge of C++
> > is just fine.

> >http://www.builderau.com.au/video/soa/Rusty-s-message-to-C-programmer...

> >http://www.builderau.com.au/video/soa/Why-C-remains-relevant/0,200006...

> > So here is an expert of who believes that you don't need C++ to
> > program low level. C++ brings extra complexity that is not needed.

> [...]

> You are not forced to use "all" the features of C++. One could
> most certainly use C++ in a kernel. However, I personally
> would avoid exceptions and global ctor/dtors like the plague.
> I also would not use the STL, oh well...

I'm not sure what you mean by "global ctor/dtors". You probably
cannot count on dynamic initialization of variables with static
lifetime, for obvious reasons, but there's certainly no reason
not to use (and a lot of reasons for using) user defined
constructors and destructors on local objects.

FWIW: Chorus was written entirely in C++ (except for the
unavoidable little bits of assembler), and that was almost 20
years ago. (Chorus was later bought by Sun, and most of its
features worked their way into Solaris, so I suspect that large
parts of Solaris are written in C++ today.)

--
James Kanze (GABI Software) email:james...@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

James Kanze

unread,
May 7, 2008, 5:36:26 AM5/7/08
to
On May 6, 3:02 pm, Joe Greer <jgr...@doubletake.com> wrote:
> Ian Collins <ian-n...@hotmail.com> wrote
> innews:68aeo1F...@mid.individual.net:

> > Why omit constructors and destructors?

> I would be interested in the answer to this myself. I know that in real
> time systems they don't want the somewhat uncontrolled flurry of activity
> that usually accompanies a method exit,

And it's more controlled if you explicitly call named functions,
rather than doing it in a destructor?

> however most OS's aren't real time and I wouldn't think that
> it would matter in the main.

The two OS's I know that are (or were) written primarily in C++
(Chorus and Symbian) both have significant support for real
time.

Joe Greer

unread,
May 7, 2008, 8:05:07 AM5/7/08
to
James Kanze <james...@gmail.com> wrote in
news:4ca7f696-bb73-499e...@a1g2000hsb.googlegroups.com:

> On May 6, 3:02 pm, Joe Greer <jgr...@doubletake.com> wrote:
>> Ian Collins <ian-n...@hotmail.com> wrote
>> innews:68aeo1F...@mid.individual.net:
>
>> > Why omit constructors and destructors?
>
>> I would be interested in the answer to this myself. I know that in
>> real time systems they don't want the somewhat uncontrolled flurry of
>> activity that usually accompanies a method exit,
>
> And it's more controlled if you explicitly call named functions,
> rather than doing it in a destructor?

Possibly. You are at least forced to think about it, since you have to
code each cleanup operation where it is going to occur. Hopefully, the
tone of my message conveyed that I thought this was a somewhat weak
argument myself, but it's the only one I had heard against destructors.

joe

Chris Thomasson

unread,
May 7, 2008, 4:24:10 PM5/7/08
to
"Ian Collins" <ian-...@hotmail.com> wrote in message
news:68aeo1F...@mid.individual.net...
> Chris Thomasson wrote:
[...]

>>
> Why omit constructors and destructors?

Well, its kind of "personal" habit. When I was messing around with using C++
in a Kernel I only made use of POD. I am not a C++ expert so I reduced my
usage of it down to bare minimum in an old toy kernel of mine. I never
experienced bugs related to how C++ features interact with kernel
environment using only POD.

Basically, I wrote that I don't use ctor/dtor because POD cannot have
user-defined ctor/dtor... Also, there were some cases in which I needed to
call the ctor/dtor from an assembly language procedure.

Chris Thomasson

unread,
May 7, 2008, 4:30:32 PM5/7/08
to
"James Kanze" <james...@gmail.com> wrote in message
news:930a9325-6d39-4c58...@s50g2000hsb.googlegroups.com...

> On May 6, 12:46 am, "Chris Thomasson" <cris...@comcast.net> wrote:
> > "Raz" <os...@gmail.com> wrote in message
> > news:715v141f46a5eg638...@4ax.com...
> > > On Wed, 30 Apr 2008 21:54:37 GMT, Erik Wikströ

> > >>Obviously his knowledge of C++ is not as good as it should be.

> > > As I said, I will find the link again. His knowledge of C++
> > > is just fine.

> > >http://www.builderau.com.au/video/soa/Rusty-s-message-to-C-programmer...

> > >http://www.builderau.com.au/video/soa/Why-C-remains-relevant/0,200006...

> > > So here is an expert of who believes that you don't need C++ to
> > > program low level. C++ brings extra complexity that is not needed.

> > [...]

> > You are not forced to use "all" the features of C++. One could
> > most certainly use C++ in a kernel. However, I personally
> > would avoid exceptions and global ctor/dtors like the plague.
> > I also would not use the STL, oh well...

> I'm not sure what you mean by "global ctor/dtors". You probably
> cannot count on dynamic initialization of variables with static
> lifetime, for obvious reasons, but there's certainly no reason
> not to use (and a lot of reasons for using) user defined
> constructors and destructors on local objects.

Yeah, your right. However, I did not use them out of habit back when I was
working on a toy x86 kernel implementation. Some objects may need to
interface with assembly language. I personally find that using POD makes can
make that process a bit easier...


> FWIW: Chorus was written entirely in C++ (except for the
> unavoidable little bits of assembler), and that was almost 20
> years ago. (Chorus was later bought by Sun, and most of its
> features worked their way into Solaris, so I suspect that large
> parts of Solaris are written in C++ today.)

Indeed.

James Kanze

unread,
May 9, 2008, 5:42:13 AM5/9/08
to
On May 7, 10:30 pm, "Chris Thomasson" <cris...@comcast.net> wrote:
> "James Kanze" <james.ka...@gmail.com> wrote in message

> news:930a9325-6d39-4c58...@s50g2000hsb.googlegroups.com...

[...]


> > I'm not sure what you mean by "global ctor/dtors". You probably
> > cannot count on dynamic initialization of variables with static
> > lifetime, for obvious reasons, but there's certainly no reason
> > not to use (and a lot of reasons for using) user defined
> > constructors and destructors on local objects.

> Yeah, your right. However, I did not use them out of habit
> back when I was working on a toy x86 kernel implementation.
> Some objects may need to interface with assembly language. I
> personally find that using POD makes can make that process a
> bit easier...

Interfacing with assembler is another theme. Throw in some
privates and publics, virtual functions and a bit of
inheritance, and figuring out the layout in assembler isn't
going to be trivial. I've never found a compiler where just
adding a constructor or destructor to what would otherwise be a
POD changed the layout in anyway, however. (On the other hand,
whatever reasons made you want a destructor could very well
impact on how you use the class in assembler. Interfacing with
assembler is one place where char[] beats std::string hands
down.)

0 new messages