Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jun 12th, 2005, 3:37 PM   #11
uman
Expert Programmer
 
Join Date: Dec 2004
Posts: 794
Rep Power: 4 uman is on a distinguished road
Ah, that's what I was asking. I'm quite aware there are pointers in C, I was asking if there was func(T& foo, T& bar); and things like that. I guess not.
uman is offline   Reply With Quote
Old Jun 12th, 2005, 3:38 PM   #12
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Kirk's example will not work as a C program.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Jun 12th, 2005, 3:48 PM   #13
kirkl_uk
Programmer
 
kirkl_uk's Avatar
 
Join Date: Apr 2005
Location: England
Posts: 86
Rep Power: 4 kirkl_uk is on a distinguished road
Send a message via MSN to kirkl_uk
Yeah, I hold my hands up to that. But anyway, the concept of what I said was right.
__________________
kirkl_uk

Last edited by kirkl_uk; Jun 12th, 2005 at 3:51 PM.
kirkl_uk is offline   Reply With Quote
Old Jun 12th, 2005, 5:47 PM   #14
Navid
Hobbyist Programmer
 
Navid's Avatar
 
Join Date: Feb 2005
Location: Canada
Posts: 187
Rep Power: 4 Navid is on a distinguished road
Send a message via MSN to Navid
Thanks for all the help
Navid is offline   Reply With Quote
Old Jun 12th, 2005, 8:07 PM   #15
grumpy
Programming Guru
 
grumpy's Avatar
 
Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,260
Rep Power: 5 grumpy will become famous soon enough
Quote:
Originally Posted by Dameon
C and C++ both have the concept of references and pointers last I checked
Incorrect.

C++ has both concepts. C only has pointers.
grumpy is offline   Reply With Quote
Old Jun 12th, 2005, 11:17 PM   #16
uman
Expert Programmer
 
Join Date: Dec 2004
Posts: 794
Rep Power: 4 uman is on a distinguished road
They ought to add references, I really like them.
uman is offline   Reply With Quote
Old Jun 13th, 2005, 1:27 AM   #17
grumpy
Programming Guru
 
grumpy's Avatar
 
Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,260
Rep Power: 5 grumpy will become famous soon enough
Quote:
Originally Posted by uman
They ought to add references, I really like them.
Such a weighty argument to justify the complexity of adding a new feature to C

IIRC, it was debated by the C standards committee during development of the 1999 C standard. They decided against adding references as the only things most C programmers would want to do with them could be done with pointers.
grumpy is offline   Reply With Quote
Old Jun 13th, 2005, 2:05 AM   #18
uman
Expert Programmer
 
Join Date: Dec 2004
Posts: 794
Rep Power: 4 uman is on a distinguished road
Yes, but I think it just looks so much nicer to see something like
change_variable_somehow(x);
rather than
change_variable_somehow(&x);
But I suppose it all depends on how you look at it. I suppose, come to think of it, that it's unnecessary.

Oh, and on a semi-related note, is a pointer-to-function to f(T&); of the same type as one to f(T); ?
uman is offline   Reply With Quote
Old Jun 13th, 2005, 3:54 AM   #19
grumpy
Programming Guru
 
grumpy's Avatar
 
Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,260
Rep Power: 5 grumpy will become famous soon enough
Quote:
Originally Posted by uman
Yes, but I think it just looks so much nicer to see something like
change_variable_somehow(x);
rather than
change_variable_somehow(&x);
You can achieve that with a macro, if you think about it.
Quote:
Originally Posted by uman
Oh, and on a semi-related note, is a pointer-to-function to f(T&); of the same type as one to f(T); ?
In C, there is no such thing as a reference type, so it is not possible to have a pointer to function that accepts a reference argument.

In C++, a pointer to a function f(T&) is of different type from a pointer to a function f(T).
[PHP]
typedef int ((*func1)(T &));
typedef int ((*func2)(T));

int f(T&);
int f(T);

int main()
{
func1 x(f);
func2 y(f);
if (x == y) // This comparison will cause a compiler error: func1 cannot be converted into a func2
{
whatever();
}
}
[/PHP]

[Oh, the joys of cross-fertilisation between C and C++ forums].
grumpy is offline   Reply With Quote
Old Jun 13th, 2005, 3:57 AM   #20
uman
Expert Programmer
 
Join Date: Dec 2004
Posts: 794
Rep Power: 4 uman is on a distinguished road
Thanks for the info.
uman is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 2:09 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC