Saturday, June 25, 2005

pointer cause decay, references do not.

Decay means loss of type information. In C and C++, an array name 'decays' to pointer to the first element. The information lost is basically the number of elements in the array. This difference should be manifested by sizeof() operator in function f() and g(). References keep that information with them. such as 'constness' of int. Function names are also said to 'decay' into pointer to the function if only function name is used. But such a function pointer retains, I think, everything about the function signature: parameter types and function return type; even in C.

With following declarations,

template < typename T > void f (T);
template < typename T > void g (T &);

and with these declarations,

double x[20];
int const seven = 7;

f(x); T is double *
g(x); T is double [20]
f(seven); T is int
g(seven); T is int const
f(7); T is int
g(7); T is int, ERROR can't pass 7 to int&

Therefore, pointer cause decay, references do not.
source: C++ Templates - The Complete Guide
by David Vandevoorde and Nicolai M. Josuttis

10 comments:

completely-complete said...

Extraordinary blog. Your site was hip and fresh
and we'll visit it again! I love surfing the internet
for blogs.
I want you to stop and compare with my 1800contacts coupon blog.

Cash Till Payday Loan In Atlanta Ga said...

Great blog. I surf the web looking for blogs like
this. Your site was on point and will be back again!
No matter when you are, just stop by and check for my 1800contacts com coupon blog site.

Cash Till Payday Loan said...

Inspiring blog. I love finding blogs this good on
the internet, when I have the time. I'm going to go
back to it!
It may look like it was hard work, but my blog was simple.

delightfully-different said...

Striking blog. I liked the site I will be back
again! Websurfing is a good way to find blogs like
yours.
I can't explain, but you need to check my 1800contacts web coupon code blog!

Instant Cash Loan Till Payday Com said...

Excellent blog. Your site was great and will be
finding it again!  I surf the net for blogs like
yours.
In my spare time I will look for your coupon codes 1800contacts blog.

lightly-blended said...

Exciting blog. The site out did itself and will be
back! I love surfing the internet for blogs that are
exactly like this blog.
Everyday of the month you need to peep my 1800contacts com coupon blog.

florida mortgage lenderf7 said...

Incredible blog. I admired your site and I will be
back once again to view it! I use much of my spare
time searching for blogs like yours.
I want you to look for my coupon codes 1800contacts blog.

quick cash advance loan1c1 said...

Unique blog my friend, I can hardly wait to vist
this site again. I just worship the site its comes
from! Believe me in my extra time I'm consistently
looking up blogs like this.
My blog, is something you need to peep out!

condensed said...

Hype blog. And I admire your site and plan on
returning to it! When I web surf it always helps me to
find great blogs.
Please go over my blog.

job opportunitya said...

Hype blog. And I admire your site and plan on
returning to it! When I web surf it always helps me to
find great blogs.
My 1800contacts com coupon blog, is something you need to peep out!