The Artima Developer Community
Sponsored Link

Heron-Centric: Ruminations of a Language Designer
x = f();
by Christopher Diggins
August 5, 2005
Summary
This is a very simple statement, but I don't like what C++ does with it.

Advertisement

In C++ the following code creates an extra temporary:

class MyClass {
  ...
  int m[1000000]
}

MyClass f() {
  MyClass ret;
  ...
  return ret;
}

int main() {
  MyClass x = f();
}
In Heron I am seriously considering rewriting code like that to behave like:
class MyClass {
  ...
  int m[1000000]
}

void f(MyClass& ret) {
  ...
}

int main() {
  MyClass x;
  f(x);
}
This avoids the creation of a superflous temporary. Could programmers live with the difference?

Talk Back!

Have an opinion? Readers have already posted 2 comments about this weblog entry. Why not add yours?

RSS Feed

If you'd like to be notified whenever Christopher Diggins adds a new entry to his weblog, subscribe to his RSS feed.

About the Blogger

Christopher Diggins is a software developer and freelance writer. Christopher loves programming, but is eternally frustrated by the shortcomings of modern programming languages. As would any reasonable person in his shoes, he decided to quit his day job to write his own ( www.heron-language.com ). Christopher is the co-author of the C++ Cookbook from O'Reilly. Christopher can be reached through his home page at www.cdiggins.com.

This weblog entry is Copyright © 2005 Christopher Diggins. All rights reserved.

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2014 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us