473,396 Members | 1,864 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

what is an escaping variable

what is an escaping variable?

Nov 12 '07 #1
46 6202
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
Nov 12 '07 #2
On Mon, 12 Nov 2007 15:46:43 -0000, C C++ C++ <m.azmath@...comwrote:
>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
Nov 12 '07 #3
On 2007-11-12 16:56:49 -0500, rp*****@yahoo.com (Roland Pibinger) said:
On Mon, 12 Nov 2007 15:46:43 -0000, C C++ C++ <m.azmath@...comwrote:
>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

Nov 12 '07 #4
On Mon, 12 Nov 2007 17:01:35 -0500, Kira Yamato
<ki*****@earthlink.netwrote:
>On 2007-11-12 16:56:49 -0500, rp*****@yahoo.com (Roland Pibinger) said:
>On Mon, 12 Nov 2007 15:46:43 -0000, C C++ C++ <m.azmath@...comwrote:
>>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?
An example of 'escaping' variables or RAII?

Nov 12 '07 #5
On 2007-11-12 17:53:53 -0500, rp*****@yahoo.com (Roland Pibinger) said:
On Mon, 12 Nov 2007 17:01:35 -0500, Kira Yamato
<ki*****@earthlink.netwrote:
>On 2007-11-12 16:56:49 -0500, rp*****@yahoo.com (Roland Pibinger) said:
>>On Mon, 12 Nov 2007 15:46:43 -0000, C C++ C++ <m.azmath@...comwrote:
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?

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.

--

-kira

Nov 12 '07 #6
On Mon, 12 Nov 2007 18:09:28 -0500, Kira Yamato wrote:
>On 2007-11-12 17:53:53 -0500, rp*****@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
"The best software is simple, elegant, and full of drama" - Grady Booch
Nov 13 '07 #7
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.

Nov 13 '07 #8
Raz

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/so...432924p,00.htm

http://www.builderau.com.au/video/so...432921p,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.

Jun 27 '08 #9
Raz wrote:

Please confine your trolling to where it belongs.

--
Ian Collins.
Jun 27 '08 #10
"Raz" <os***@gmail.comwrote in message
news:71********************************@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/so...432924p,00.htm

http://www.builderau.com.au/video/so...432921p,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...

Jun 27 '08 #11
On Tue, 06 May 2008 10:27:14 +1200, Ian Collins <ia******@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?

Jun 27 '08 #12
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
Jun 27 '08 #13
Razi wrote:
Ian Collins <ia******@hotmail.comwrote:
>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?
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 **
Jun 27 '08 #14
On Mon, 05 May 2008 20:19:18 -0400, CBFalconer <cb********@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?
Jun 27 '08 #15
On Mon, 05 May 2008 16:40:04 -0700, "Peter Duniho"
<Np*********@nnowslpianmk.comwrote:
>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.
Jun 27 '08 #16
Razii wrote:
CBFalconer <cb********@yahoo.comwrote:
>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.

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

** Posted from http://www.teranews.com **
Jun 27 '08 #17
Razii wrote:
On Mon, 05 May 2008 20:19:18 -0400, CBFalconer
<cb********@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.
Jun 27 '08 #18
On Mon, 5 May 2008 20:51:12 -0700, "Mike Schilling"
<ms*************@hotmail.comwrote:
>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.

Jun 27 '08 #19
"Mike Schilling" <ms*************@hotmail.comwrote in message
news:RA*****************@nlpi069.nbdc.sbc.com...
Razii wrote:
>On Mon, 05 May 2008 20:19:18 -0400, CBFalconer <cb********@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....bdc76f9792de1f
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...

:^/

Jun 27 '08 #20

"Chris Thomasson" <cr*****@comcast.netwrote in message
news:_e******************************@comcast.com. ..
"Raz" <os***@gmail.comwrote in message
news:71********************************@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/so...432924p,00.htm

http://www.builderau.com.au/video/so...432921p,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...

Jun 27 '08 #21
Razi wrote:
On Mon, 5 May 2008 20:51:12 -0700, "Mike Schilling"
<ms*************@hotmail.comwrote:
>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?
Jun 27 '08 #22
"cr88192" <cr*****@NOSPAM.hotmail.comwrote in message
news:51**************************@saipan.com...
>
"Chris Thomasson" <cr*****@comcast.netwrote in message
news:_e******************************@comcast.com. ..
>"Raz" <os***@gmail.comwrote in message
news:71********************************@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/so...432924p,00.htm

http://www.builderau.com.au/video/so...432921p,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":

struct [kobject_name_POD] {
[state];

void ctor() {
}

void dtor() throw() {
}

[kobject_name_POD_API];
};
Think in terms of:
http://groups.google.com/group/comp....106926ba5db19f

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....106926ba5db19f
;^)
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...

Jun 27 '08 #23
"Chris Thomasson" <cr*****@comcast.netwrote in message
news:34******************************@comcast.com. ..
"Mike Schilling" <ms*************@hotmail.comwrote in message
news:RA*****************@nlpi069.nbdc.sbc.com...
>Razii wrote:
>>On Mon, 05 May 2008 20:19:18 -0400, CBFalconer <cb********@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....bdc76f9792de1f
[...]

Oh yeah, region allocator in C is simple:

http://groups.google.com/group/comp....f65273b09b4229

Jun 27 '08 #24
Chris Thomasson wrote:
"cr88192" <cr*****@NOSPAM.hotmail.comwrote in message
news:51**************************@saipan.com...
>>
"Chris Thomasson" <cr*****@comcast.netwrote in message
news:_e******************************@comcast.com ...
>>"Raz" <os***@gmail.comwrote in message
news:71********************************@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/so...432924p,00.htm
http://www.builderau.com.au/video/so...432921p,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.
Jun 27 '08 #25
Razii <hj**@gmail.comwrites:
On Mon, 5 May 2008 23:37:03 -0700, "Mike Schilling"
<ms*************@hotmail.comwrote:
>>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"
Jun 27 '08 #26
Keith Thompson wrote:
Razii <hj**@gmail.comwrites:
>On Mon, 5 May 2008 23:37:03 -0700, "Mike Schilling"
<ms*************@hotmail.comwrote:
>>>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.

Jun 27 '08 #27
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

Jun 27 '08 #28
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.
Jun 27 '08 #29
Ian Collins <ia******@hotmail.comwrote in
news:68**************@mid.individual.net:
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.
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
Jun 27 '08 #30
Ian Collins <ia******@hotmail.comwrote in
news:68*************@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
Jun 27 '08 #31
Ian Collins <ia******@hotmail.comwrites:
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.
Some of that is addressed here:
http://www.microsoft.com/whdc/driver/kernel/KMcode.mspx
Jun 27 '08 #32
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
Jun 27 '08 #33
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
Jun 27 '08 #34
ma**@pulsesoft.com wrote:
Ian Collins <ia******@hotmail.comwrites:
>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.

--
Ian Collins.
Jun 27 '08 #35
Ian Collins <ia******@hotmail.comwrites:
ma**@pulsesoft.com wrote:
>Ian Collins <ia******@hotmail.comwrites:
>>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.

--
mailto:av****@comtv.ru
Jun 27 '08 #36
ma**@pulsesoft.com wrote:
Ian Collins <ia******@hotmail.comwrites:
>ma**@pulsesoft.com wrote:
>>Ian Collins <ia******@hotmail.comwrites:

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.
Not if you use the right tool for the job.

--
Ian Collins.
Jun 27 '08 #37
On 6 Maj, 23:11, m...@pulsesoft.com wrote:
Ian Collins <ian-n...@hotmail.comwrites:
m...@pulsesoft.com wrote:
Ian Collins <ian-n...@hotmail.comwrites:
>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) thenyou
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
Jun 27 '08 #38
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.
Jun 27 '08 #39
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.

Jun 27 '08 #40
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

Jun 27 '08 #41
On May 6, 12:46 am, "Chris Thomasson" <cris...@comcast.netwrote:
"Raz" <os...@gmail.comwrote in message
news:71********************************@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/so...o-C-programmer...
http://www.builderau.com.au/video/so...evant/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:ja*********@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
Jun 27 '08 #42
On May 6, 3:02 pm, Joe Greer <jgr...@doubletake.comwrote:
Ian Collins <ian-n...@hotmail.comwrote
innews:68*************@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.

--
James Kanze (GABI Software) email:ja*********@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
Jun 27 '08 #43
James Kanze <ja*********@gmail.comwrote in
news:4c**********************************@a1g2000h sb.googlegroups.com:
On May 6, 3:02 pm, Joe Greer <jgr...@doubletake.comwrote:
>Ian Collins <ian-n...@hotmail.comwrote
innews:68*************@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
Jun 27 '08 #44
"Ian Collins" <ia******@hotmail.comwrote in message
news:68*************@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.

Jun 27 '08 #45
"James Kanze" <ja*********@gmail.comwrote in message
news:93**********************************@s50g2000 hsb.googlegroups.com...
On May 6, 12:46 am, "Chris Thomasson" <cris...@comcast.netwrote:
"Raz" <os...@gmail.comwrote in message
news:71********************************@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/so...o-C-programmer...
>http://www.builderau.com.au/video/so...evant/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.

Jun 27 '08 #46
On May 7, 10:30 pm, "Chris Thomasson" <cris...@comcast.netwrote:
"James Kanze" <james.ka...@gmail.comwrote in message
news:93**********************************@s50g2000 hsb.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.)

--
James Kanze (GABI Software) email:ja*********@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
Jun 27 '08 #47

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Derek Fountain | last post by:
I was just writing a sanitisation route for a bit of user input. The data is an English text description of a product, and will go into a DB, then back out to other user's browsers. As per...
0
by: Lisa | last post by:
I need to apply the HTML formatting tags and the French accented characters in a XML document. The XML is generated from a database that has HTML tags and French accented characters in the records....
5
by: Aloysio Figueiredo | last post by:
I need to replace every ocurrence of '/' in s by '\/' in order to create a file named s. My first attempt was: s = '\/'.join(s.split('/')) but it doesn't work: >>> s = 'a/b' >>> s =...
5
by: bobbyballgame | last post by:
I am having a problem calling Stored Procedures: .... dim MyValue, MyOtherValue MyValue = "Bobby's value" MyOtherValue = Bobby's other value" rs.Open "exec MyStoredProc """ & MyValue &...
6
by: Joe Price | last post by:
Hi all I've formatted one of my xml files for viewing through a web browser using xsl. It works fine in Internet Explorer, however when I use Netscape6 or Opera to view the same page the...
5
by: Troot | last post by:
Hi All, I was wondering if someone could clear this up for me. I have constructed a sample for a bigger problem I'm having. So, given the xml file: <?xml-stylesheet href="test.xsl"...
4
by: Jon | last post by:
Hi, I used XslCompiledTransform with the following Xsl file. The <xsl:text disable-output-escaping="yes"does not work when using XslCompiledTransform to do the trnasform (namely the output...
1
by: David Henderson | last post by:
I know 'disable-output-escaping' has been discussed in the past, but I can't put my finger on any of the threads to see if my current problem is addressed. Sorry for re-asking the question if it...
2
by: mister-Ed | last post by:
I have a datagrid, and when initializing my field variables, I need to double up apostrophes so they are accepted into SQL dbase. In the line below, i'm trying to do this with the Replace function,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.