Are there any 8051 C++ compilers ? - Page 4

Do you have a question? Post it now! No Registration Necessary

Translate This Thread From English to

Threaded View
Re: Are there any 8051 C++ compilers ?

Quoted text here. Click to load it

Not that I agree or disagree...

But could we please keep c.a.e free of political drivel?  I get enough
of that with the rock and movie stars (and "<!-- insert
agenda-driven-group -->) opinionating.  Must we (I) get it here too?  

Just a suggestion -- if y'all want it, go for it!

--
Dan Henry

Re: Are there any 8051 C++ compilers ?
Quoted text here. Click to load it

As long as it is just a signature I personally don't really care and
would advise anyone not to care either ;-)
Admittedly, as soon as political discussion started here I wouldn't
like it either.

Just my personal opinion about this. (Without saying whether I agree
with the signature or not;)

Regards,
johannes

Re: Are there any 8051 C++ compilers ?
Quoted text here. Click to load it
This last one should be the other way around shouldn't it?

Robert

Re: Are there any 8051 C++ compilers ?
Quoted text here. Click to load it

No.  The C const is peculiar, and effectively means write
protect.  The i can't be used in constant expressions, such as
array sizes.  Try the C faq for details, or the standard.

The point is C is not a subset of C++.  They are different
languages with superficial similarities.

--
"The most amazing achievement of the computer software industry
 is its continuing cancellation of the steady and staggering
We've slightly trimmed the long signature. Click to see the full one.
Re: Are there any 8051 C++ compilers ?

Quoted text here. Click to load it

Why is that peculiar?  Would you prefer it was spelled
"readonly" or somesuch?  I find it extremely useful for placing
look-up tables and the like into ROM rather than RAM.

Quoted text here. Click to load it

Ah. You think it should be a compile-time constant (like
Pascal's) rather than a run-time constant?  

Quoted text here. Click to load it

That's definitly true.

--
Grant Edwards                   grante             Yow!  I always have fun
                                  at               because I'm out of my
We've slightly trimmed the long signature. Click to see the full one.
Re: Are there any 8051 C++ compilers ?
Quoted text here. Click to load it

No, I don't think anything.  The point is that is not a real
compile time constant, unlike C++.  Read the C faq.

--
"The most amazing achievement of the computer software industry
 is its continuing cancellation of the steady and staggering
We've slightly trimmed the long signature. Click to see the full one.
Re: Are there any 8051 C++ compilers ?

Quoted text here. Click to load it

I know the difference, I just don't understand why it's the C
implimentation of const that's "peculiar" instead of the C++
const being "peculair".  Using the term "peculiar" led me to
believe that you thought it somehow violated your (or the
world's) expectations and didn't do what it should.

--
Grant Edwards                   grante             Yow!  Now KEN and BARBIE
                                  at               are PERMANENTLY ADDICTED to
We've slightly trimmed the long signature. Click to see the full one.
Re: Are there any 8051 C++ compilers ?

[...]
Quoted text here. Click to load it

Consider:

   const int array_size = 10;
   int array[array_size];

The latter declaration is illegal (at file scope) in C, but perfectly
legal C++.  consts aren't (in C).

Regards,

                               -=Dave
--
Change is inevitable, progress is not.

Re: Are there any 8051 C++ compilers ?
Quoted text here. Click to load it
                               -=Dave

C++ gave const a meaning that didn't fit into the C (or the intuitive)
definition: read only. C++ seems to think it should be a replacement for
#define or enum. const shouldn't be construed to be a poor man's macro.
Somthing else (what? I don't know) should be used instead.

But hey! I'm just a poor compiler crafter looking for a bar fight. ;-)

-Rich



--
Richard Pennington
Email: snipped-for-privacy@pennware.com
We've slightly trimmed the long signature. Click to see the full one.
Re: Are there any 8051 C++ compilers ?

Quoted text here. Click to load it


Actually, Stroustrup wanted the compiler to have *more* information for static
type-checking.  He lamented the fact that he couldn't completely remove the C
pre-processor, altogether.

This usage in C++, that of a 'const int' for example, could (if the C+ linker
would support it) remove the instance of storage if the address isn't taken.  In
that sense, it could be very useful without incurring a price.  But I don't know
of any C++ compiler/linker sets that are able to do this, so a const in C++ will
take up a memory instance, even if the value is known by all modules at compile
time and the address isn't ever needed, at all.  Stroustrup, again, insists that
it's certainly within the spec to eliminate const's whose addresses aren't taken
by any module.  But none I've used manage this.

Jon

Re: Are there any 8051 C++ compilers ?
(Comments below)

Quoted text here. Click to load it

I understand how const is used in C++. I was just suggesting a different
syntax might have been a good idea to avoid unnecessary confusion with C.

I really would have liked it if C++ could really be a superset of C.
That is, where things that look the same, act the same.

I know a lot of people who refuse to use C++ (we are embedded
programmers after all!) who would really benefit from using a C++
compiler for "plain old C". Then, who knows, they might add a class or two!

Quoted text here. Click to load it
In
Quoted text here. Click to load it
know
Quoted text here. Click to load it
will
Quoted text here. Click to load it
that
Quoted text here. Click to load it
taken
Quoted text here. Click to load it

I'm currently working on a compiler system that will be able to do this,
but since it is a project in my spare time, it will probably be
available around 2020. ;-) There is more information on my web site...
Follow the link to PFX.

Quoted text here. Click to load it

-Rich

--
Richard Pennington
Email: snipped-for-privacy@pennware.com
We've slightly trimmed the long signature. Click to see the full one.
Re: Are there any 8051 C++ compilers ?

Quoted text here. Click to load it

Just a historical detail. const - with its current semantics - was
introduced into C++ well before the C committee added a const with
different, and less useful, semantics. Maybe the C committee should
have decided on compatibility or used a different syntax to avoid
unnecessary confusion with C++.

Quoted text here. Click to load it

Yes. That would be very nice. See
http://www.research.att.com/~bs/bs_faq.html#merge

Quoted text here. Click to load it

You might like to consider the ISO C++ committee's technical report on
performance issues. It addresses a lot of issues related to embedded
systems: http://www.research.att.com/~bs/performanceTR.pdf

  -- Bjarne Stroustrup; http://www.research.att.com/~bs

Re: Are there any 8051 C++ compilers ?
[snip]
Quoted text here. Click to load it

I wish I had been more aware of that process as it was going on. I was
completely stuck in C at that time.

Quoted text here. Click to load it

Thanks for reminding me of that. I'd read that before and completely
agree, obviously.

Quoted text here. Click to load it

Thanks for pointing that out, I hadn't seen it before.

It's kind of funny how much resistance to change I've seen during my
career. I started out writing C compilers for 8 bit micros in the '80s.
At that time "everyone" was certain that C could never replace assembly
in those applications. I think it took several years, as new graduates
got into the swing of things, before C became readily acceptable.

One ramification of that change was that technical support questions
changed. A typical question originally was "How can I determine my
maximum stack usage?" This question morphed over time into a long
discussion that, in the middle, after asking the user about their stack
usage, resulted in the question "What is a stack?"

For the last many years that battle has become C vs. C++. It is still
raging. I currently work for a large medical equipment company. We are
just now starting to use C++ extensively for embedded development.
It took a long time before everyone could become comfortable with all
of C++'s "hidden overhead". Unfortunately, part of the problem is that
many people take the hidden overhead for granted without actually
understanding what and where it is.

I have a book (the name of one of the authors is strikingly similar to
yours) called "The Annotated C++ Reference Manual"
(Ellis and Stroustrup, 1990). I recommend this book to everyone I can
because it explains why and how the language works, even down to
how a compiler might implement a language feature. An outstanding book
for someone wanting to know how C++ works, rather than just how to use
C++.

Quoted text here. Click to load it

-Rich

--
Richard Pennington
Email: snipped-for-privacy@pennware.com
We've slightly trimmed the long signature. Click to see the full one.
Re: Are there any 8051 C++ compilers ?


Quoted text here. Click to load it

Thanks! Very useful document.

--
Guy Macon <http://www.guymacon.com


Re: Are there any 8051 C++ compilers ?
Quoted text here. Click to load it
In
Quoted text here. Click to load it
know
Quoted text here. Click to load it
will
Quoted text here. Click to load it
that
Quoted text here. Click to load it
taken
Quoted text here. Click to load it

Odd. My impression was that with the exception of old GCCs, all C++
compilers avoids laying down storage for simple consts, such as

      const int a = 7;

Even the first C++ compiler, Cfront, did that 20 years ago.

 -- Bjarne Stroustrup; http://www.research.att.com/~bs


Quoted text here. Click to load it

Re: Are there any 8051 C++ compilers ?
Quoted text here. Click to load it
In
Quoted text here. Click to load it
know
Quoted text here. Click to load it
will
Quoted text here. Click to load it
that
Quoted text here. Click to load it
taken
Quoted text here. Click to load it

That was my impression, too, but I haven't exhaustively tested.  For
what it's worth, here's what g++ version 3.2.2 did.  From this input file:

#include <iostream>

const int seven = 7;
const int eight = 8;
const int unused = 99;

int main()
{
     std::cout << "seven plus eight is " << seven+eight << std::endl;
     return 0;
}

I get an assembly file which includes the following:

    pushl    $_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_
    subl    $12, %esp
    pushl    $15           ; note that this is the constant 15
    subl    $12, %esp
    pushl    $.LC0          ; .LCO is the address of the string
    pushl    $_ZSt4cout
.LCFI3:
    call    _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
    

When I look at the binary (running under Linux), I get:

                              7365 7665 6e20 706c  ........seven pl
00007b0: 7573 2065 6967 6874 2069 7320 0000 0000  us eight is ....
00007c0: 0700 0000 0800 0000 011b 033b 2800 0000  ...........;(...
00007d0: 0400 0000 78fe ffff 4800 0000

As you can see, the constants 7 and 8 seem to be present, but the
constant 99 is not.  I used no command line parameters for optimization,
so perhaps there is a way to tell it to suppress the creation of these
constants.

Ed


Re: Are there any 8051 C++ compilers ?
Quoted text here. Click to load it

I am surprised to see the 7 and 8 at all - I would have expected
the compiler to do compile time computations and have generated
load 15.  I am not surprised that 99 is missing, it was never
used.  So I expect your hex dump at 07c0 and 07c2 is of something
else, such as symbol tables.  Try using objdump -dS

--
"Churchill and Bush can both be considered wartime leaders, just
 as Secretariat and Mr Ed were both horses." -     James Rhodes.



Re: Are there any 8051 C++ compilers ?
Quoted text here. Click to load it

It did load a 15 directly if you examine the assembly version (with my
comments added), but it still left the 7 and 8 in a data section.

Quoted text here. Click to load it

Since this is data, better is objdump -sx which dumps the contents of
each section.  Here's the .rodata section:

Contents of section .rodata:
  80487a0 03000000 01000200 73657665 6e20706c  ........seven pl
  80487b0 75732065 69676874 20697320 00000000  us eight is ....
  80487c0 07000000 08000000                    ........

They're really there.  Once again, I should point out that this is with
no command line options, so no optimizations are turned on.  When I turn
on the lowest level of optimization (-O1), they all go away:

Contents of section .rodata:
  80487f4 03000000 01000200 73657665 6e20706c  ........seven pl
  8048804 75732065 69676874 20697320 00        us eight is .

Ed


Re: Are there any 8051 C++ compilers ?

Quoted text here. Click to load it

This is much as you would expect. With no optimization, information is
left unesturbed to ease debugging. Things like elimination of
redundant constants and inlining is often (most often?) left to an
optimizer.

I have had people complain about the performance of C++, just to find
that they were measuring code running in debug mode (which often
leaves the code 100 larger and 25 times slower on a PC).

Again: eliminating storage for simple consts is trivial, was done as
early as 20 years ago, and is to the best of my knowledge done in all
modern compilers.

  -- Bjarne Stroustrup; http://www.research.att.com/~bs

Re: Are there any 8051 C++ compilers ?

Quoted text here. Click to load it

Ed,

would you please try again with optimization level -O2?

You can get an assembly listing of the generated code by adding

 -Wa,-ahlms=myfile.lst

to the compiler command line.

Tauno Voipio
tauno voipio (at) iki fi



Site Timeline