-
Well actually I haven't learned c++ from reading a book or any direct learning tool, just my math and algebra readings in what has relation with the computer, ok if I stuck in anything I have my references but generally I look to the c++ language from the logic side, I belive it's the best logic language, and in our case here I said logically we can't pass 100 to 50 , the concept of passing arrays by reference is the default doesn't implies for me to make the array a pointer, array has no relation with pointer, a simple difference an array exists in a static location but pointer I can change its location to anywhere .. I belive also that nothing is perfect and c++ still needs some mathematical solutions to solve some of its problems ..
when you have time please take a look at this :
http://forums.devx.com/showthread.php?t=157789&page=1
maybe you have a suggestion to tell.
-
Well it has to do more with why C++ was designed. C++ was designed as a generic programming language. For pure logic / mathematical languages, try Lisp or Prolog. They are excellent languages, very rich in their own sense. And you can use them in your C++ apps (provided you get the libraries to use them). They are usually interpreted (in fact always).
-
 Originally Posted by Amahdy
Sorry I don't mean bug exactly, I mean something that we can't solve so we put it like that -just for now- ..
It's deliberate, not a bug. A safer way to represent an array in programming language is packing the array within a struct that contains the first element's address and another variable that stores the array's size. However, this means that instead of passing a pointer (which is what C and C++ do today when you pass an array to and from a function), you would be passing a struct, and that's significantly less efficient. So the decision was between efficiency and safety, and as C usually does in such cases, efficiency wins. So, yes, the decaying of arrays into pointers can lead to bugs but then again, it's the fastest way to manipulate arrays. That's why C and C++ are for "serious programmers", as Bjarne Stroustrup has said many times.
Danny Kalev
-
Razee I wasn't asking for a "for math" language, I already use the prolog for the AI programming, and I use C++ for my developments projects ... I was just explaining that I take everything in c++ by the logic but for our special case here and because nothing is perfect ; we can't apply logic here and 100 could be passed to 50 ; just because 50 is actually a pointer and not a true 50 ...
anyway I still belive that it needs an upgreat to get a better sense and keep the speed as fast as it now for passing the arguments.
-
In C++, if you want to pass a whole array instead of just a pointer, you can use the STL containers. But again, it is a huge waste to pass huge data structures by value unless you really need to do that.
-
well as Danny pointed, if we don't use a pointer we may need to pass a structure that contains address and size ... but what if we change the compiler designe such that it's him who do that ... something like :
if specified size in function arguments is NOT-EQUAL the caller size pop-up an error, and why an error ? JUST TO MAKE THIS "FORM" OF ARGUMENT HAS A SENSE !!!
and after that like every array, the compiler should declare this argument as an array specifing a fixed size for it ... and because we are sure that the caller is calling this function from an equal size array we don't have any problems inside the function...
or if the user want not to specify a fixed size he may just use this : arr[] or *arr or any thing that has a good sense ...
Just suggestions nothing more !
-
There could be things like incompatibilities with earlier C/++ programs if you make such a change to the compiler. Maybe new programming languages will implement that.
Similar Threads
-
Replies: 11
Last Post: 07-16-2007, 09:36 PM
-
By Patrick Comeau in forum VB Classic
Replies: 6
Last Post: 03-22-2001, 11:50 PM
-
By Mark Alexander Bertenshaw in forum VB Classic
Replies: 10
Last Post: 06-16-2000, 05:34 AM
-
By Mark Alexander Bertenshaw in forum VB Classic
Replies: 0
Last Post: 06-12-2000, 08:15 PM
-
By Kunal Sharma in forum VB Classic
Replies: 2
Last Post: 04-25-2000, 03:45 PM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Development Centers
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center
|