c++, c# and pointers

Started by
1 comment, last by AlbertoT 21 years, 2 months ago
Hello to everybody it seems that c# is slight slower than c++ but much easier to use. If so ,I switch to c# immediatly. Being an amateur I do not care about performance. However I understood that c# does not use pointers or , better said, it does not encourage the use of pointers ( unsafe coding or something like that )while all the game programming books I own ,make an extensive use of pointers. It is well known that very often programmers abuse of pointers. in other words they use them even when they are not strictly necessary. On the other hand in some other case pointers are a must, unless of course you are willing to accept serious costraints. In conlusion what about c++, c# and pointers ? thanks in advance
Advertisement
C++ uses pointers mostly because that was the only way in C to get reference semantics. In C#, almost everything is accessed through references, so it has little need for pointers in most scenarios.
In the niche scenarios where you do need pointers, you can have them in special sections of code marked as unsafe.


"I know very well who Satan is: He is freedom. He is the uncontrolled, the incalculable, the antithesis of order and discipline, the antithesis of the legalism of outer space.... We know where a planet will be in twelve years, four months and nine days. But we don''t know where a butterfly will have flown one minute hence. Therefore the butterfly is of Satan."
-- Jens Bjørneboe
--AnkhSVN - A Visual Studio .NET Addin for the Subversion version control system.[Project site] [IRC channel] [Blog]
Well, actually references ARE pointers :-)

What C# does not support is pointer arithmetics - this pointer++ stuff etc. A reference is a pointer - you can assign it (validly), and it can be invalid (null). But with missing pointer arithmetics, you can never make a valid pointer point to invalid space (thanks to the GC, too).


Regards

Thomas Tomiczek
THONA Consulting Ltd.
(Microsoft MVP C#/.NET)
RegardsThomas TomiczekTHONA Consulting Ltd.(Microsoft MVP C#/.NET)

This topic is closed to new replies.

Advertisement