|
-
Aug 20th, 2001, 10:57 AM
#1
Thread Starter
New Member
What makes C and C++ what they are?
Hi everyone, if you dont mind I would like us to have a long discussion about the 2 programming languages C and C++. Why am i saying this on a VB site, well I am a VB user and I have been learning C++. There is a great difference in the two languages and I wanna know all there is about why C++ is just a good as everyone says it is.WARNING I AM NOT A C++ EXPERT SO I MAY MAKE MISTAKES HERE BE EASY.
To be honest I am against C++ for ONE thing: the syntax. Some of you may have seen the obfuscated C code competition somewhere on the net (www.ioccc.org). The things you can write with this language, God have mercy. Here is a short clip of some C code ( dont ask me what it does, I dunno and dont wanna know)
[x] );
} p(H,
H,r );
F; x;
) { E S=
e ; w l =
" !{ ,;lf6D@"
; j X 1-g; F; *++l;
){ *S++ =*j; j X*l%3*g-
g+*l%5*b-3*b; } y =M x-G);
y =M-J)* M-x)+ M-J-1)*y+.01; y=
sqrt((u+q[--x]+.1)/y ); o-=T; C i)+
#define Z(x)(t(0,(x-C)/y)-l+1e-6*(x-Q))
.5; K=M-B); { N f=I,Q=0; F; f-Q>c; ){ P l=0
; N H = C+c/2+1; H%=c; H X(f+Q+c-2*H)/2/c*c; l=
Z(Q); O=(A-W)*Z(H)/Z(f); _(O,R=B?K>= H:L/k>O+W); *(
R?&Q:&f)=H; } Q X f; *S=*j=Q/=2; s=B?s:Q+k; f=Q+n[x/z];
n[x/z]=x%z+J%(z*2/g)?f:!putc(x?l[4*g*f/z/z/I-8]:10,stderr);
H-=U; F O=156; O--; ){ H--; *H=e[O%U]*e[O/U]/y+.8**H; } C-=Q+.5
; y i/.9)-Q-C; p(p(r+T,r,r),H,r); h[x]=.7*h[x]+C*C; u X h[x]; u*=.7
; d X C>0?-y:y; } } j X 9; } _(_(x,x),x); } D 0; }
Now I know that people never write programs like that but I have seen some well formatted code thats not as attractive as it could be. Somebody one day just count how many operators you have in your C/C++ code in you'll see what I mean.
Then there are the little oddities such as the blasted semi-colon.
Compilers know when you have left it out and even know where it should have gone. Now somebody correct me if I am wrong, cant the compiler add it for you (in most cases). i can see what advantages the compiler has coz of it but in some cases I dont know why its needed. Somebody tell me whats wrong with this code:
class SomeUseLessThing
{
public:
int a;
void fn1(int b);
private;
int c;}
Forgive me if I am wrong but on one of those days, if you looked at the above code without the compiler there it would look fine. Even as you code it and finish things look pretty okay, try and compile then BAM!!!! "private;" should be "private:" and that the last brace should have a ; following it so the line would be "int c;};"
Following on, is the bracket. Its very much easier to type when compared to words in other languages such as Pascal's begin and end or VB's: Function BlahBlah()....End Function. But however its much harder to spot and pair up, especially when there loads:
int Function(int a, int b){//i hate this bracket's position
{/*block1*/ int c=23;{
/*block2*/ int e=12;} int f=12} int g=23}
These are some of the things, and give a beginner one or two of those for a couple of hours and boy are they in for a long night.
Now DONT BE MISTAKEN I KNOW THERE ARE GOOD THINGS ABOUT THIS LANGUAGE AS WELL.
I have evaluated it on other counts and it measures up. For instance the speed thing, I am a performance super freak so when it comes to writing super fast speed bombs, naturally C++ would be the pick. Only thing is, C++ isnt exactly a toy language. Learning the ins and outs of the beast will take long and I know the journey WILL NOT BE EASY.
Oh they are about to close the library just now, so thats it for now. Please give me your feelings on this language, share your experiences, likes and dislikes and we'll pickup again on it later.
Ps: wanna know why I want all these ideas and opinions? I want to create a better C++, a more readable but by all means just as powerful language. I have been working on it now for 3 months or so. What do you get when you cross breed C++ and VB well the answer is not a.(java) or b.(c#) its c.(Ciyana). Thats the code name of the language while its under development. Anyone interested please contact me( [email protected]). Here is an excerpt for hello world.
Public Function Main()
Reserve String StorageFor Msg = "Hello World"
Console.Write (Join(Msg, "From Ciyana"))
// the output is : Hello World From Ciyana
End Function
-
Aug 20th, 2001, 12:43 PM
#2
Frenzied Member
Okay, you are going to write a new language, yet you are just learning C? I don't think that is such a good idea.
C/C++ is not the world's best language. It is a bit old and has some problems, but it is much better than VB. Before I go into why, let me tell you that the introduction of Java and C# has prompted the upgrade of C/C++. The new language, which is being tenatively refferred to as D, will be out in a year or so.
Okay, the people who wrote the language, weren't trying to make it human readable. That wasn't their goal. They weren't going for a nice cuddly language. If you don't like that, then too damned bad. The new language won't be cuddly either. There are cuddly languages out there, and that is a good project, but it wasn't why we have C/C++.
I like the syntax because int myInt; is shorter than Dim myInt as Integer. Also, we have ++, --, %, +=, -=, for structures that have much more flexiblity, classes, ==, [b]scoping[b], malloc, AND POINTERS.
In C++ (and my favorite language Perl) you can do things like...
Code:
for(t = 0, x = 0, y = 0; y < 100; ) { x = t++ * 2; y+=x;}
Now, I can't think of a time when I need to do that, but it is legit. The semicolons let me put more than one statement on a line, and the braces let me put the block any damned where I please. 
To do that in VB...
Code:
t = 0
x = 0
for y = 0 to 100 - 1 Step 0
x = t * 2
t = t + 1
y = y + x
next
'Course, syntax doesn't make a language. VB has serious problems with scoping, memory allocation, and pionters.
Anyway, if you want to have much fun, learn Perl when you are done with C.
PS, your code sample...
Code:
Public Function Main()
Reserve String StorageFor Msg = "Hello World"
Console.Write (Join(Msg, "From Ciyana"))
// the output is : Hello World From Ciyana
End Function
The output should be "Hello WorldFrom Ciyana". I don't want to learn how to remove spaces that a join function adds.
Travis, Kung Foo Journeyman
As always, RTFM.
WWW Standards: HTML 4.01, CSS Level 2, ECMA 262 Bindings to DOM Level 1, JavaScript 1.3 Guide and Reference
Perl: Learn Perl, Llama, Camel, Cookbook, Perl Monks, Perl Mongers, O'Reilly's Perl.com, ActiveState, CPAN, TPJ, and use Perl;
YBMS, but Mozilla doesn't.
-
Aug 20th, 2001, 12:57 PM
#3
Fanatic Member
The semicolon thing: The compiler doesn't know exactly where it goes, it just guesses. If it did know, you wouldn't have to put it in, the compiler would just add them in for you.
Brackets: Just format your code nicely. It's not that hard.
Code:
int function()
{
for (int i = 0; i <= 10; i++)
{
if (someVar == otherVar)
{
cout<<"equal"<<endl;
anotherVar++;
}
}
return anotherVar;
}
If you are going to write another C++, I would stick to the C++ brackets as they are easier to type than VB's keywords. Something like this maybe:
Code:
Public Function Main()
{
Reserve String StorageFor Msg = "Hello World "
Console.Write (Join(Msg, "From Ciyana"))
// the output is : Hello World From Ciyana
}
Alcohol & calculus don't mix.
Never drink & derive.
-
Aug 20th, 2001, 01:12 PM
#4
transcendental analytic
VB doesn't have any "pointers", they are all hided in the variables so that the user won't go do any stupid mistakes which you pretty easily can do in C++. Using Copymemory and a string or array in a UDT structure you can though simulate pointers but it's pretty awkward, nothing to recommend except in special cases.
the semicolons deliminates each statement, not the linefeeds or colons like in vb. Vb colons won't deliminate all statements either.
Whitespaces and linefeeds are ignored in C++, which means you just put them to tide up your code.
If you are interested in speed, C++ let's you do a lot of lowlevel operations, pointeraritmetics and even inline ASM. Inlining methods makes your code run faster as functions are not called and so the stackprocessing parts are skipped, instead their contents are expanded, that is copied into the position where they are called. C++ classes are structures, that is equivalent with UDT types in VB, so access to them is tons faster and they don't take up any extra space like COM objects do.
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Aug 20th, 2001, 01:31 PM
#5
transcendental analytic
Brackets are not for tidying up code, Brackets are used for enclosing
1. namespaces
2. class contents
3. function contents
4. if and else, switch, for contents
5. locally used variables
there's probably something else i'm missing but these are most general.
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Aug 20th, 2001, 01:32 PM
#6
Member
Brackets can make blocks of code easier to separate from other code.
-
Aug 20th, 2001, 01:35 PM
#7
PowerPoster
Originally posted by CiberTHuG
In C++ (and my favorite language Perl)
Perl rules!
-
Aug 20th, 2001, 01:35 PM
#8
transcendental analytic
Those brackets actually make the variables inside them local
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Aug 20th, 2001, 01:35 PM
#9
I hate to hear people talk about C/C++ in a bad way. These are two very powerful programming languages. Although VB is a very nice frontend for business applications, very few retail apps are written using VB. C and C++ give the developer fast, powerful operation on a user's machine. They have amazing graphics capabilities, as well as the ability to do alot of low-level programming. Pointers are extremely useful in C/C++, and I sometimes have to write many lines of extra VB code, when in C I would just use a pointer.
The Difference between C anc C++ is that C++ is an object-oriented programming language, while C is not. I am pretty proficient in C, although my C++ is limited.
I, personally, have seen many programmers try learning VB as their first language, and it is horible. They sometimes can do a job here or there, but they do not really understand what they are doing. By learning C first, you get an idea of what a programming language is all about. You understand what can and cannot be done from a software level, and also understand what is going on in your VB app.
I tried learning VB before C. I was not bad and wrote a few programs. After learning C, I realized that my previous skill sucked. By learning C, my VB skills became immediately more proficient. I learned how to use VB to get the most power out of it. I also learned that VB is best used for Database-driven business and web applications. When it comes down to making retail applications such as productivity tools, net apps, or games, VB just can't seem to cut it most of the time. When you have to start using numerous APIs, you must think about using C++ instead. VB wasn't intended to be used primarily with APIs. Yes, they are available, and Microsoft Documentation tells u to use them sometimes, but that is not the purpose of VB. The APIs are there to allow you to use a few Windows features in VB that you may want to use, even though VB does not support them. But when u look through most of the software that is out there (multimedia, filesharing, games...) you will see they are mostly made in C++ (along with some in JAVA). There is a reason for this. Shawn Fanning (of Napster) could have used VB. He may have even used it to create some DLLs for all I know. But C++'s libraries make it much easier to do the job.
The bottom line is, VB is not a bad language. It simplifies many tasks that would take longer if done in C. But when you start trying to create massive multimedia apps or games or the like, productivity will lag. Additionally, if you do not know a lower-level language like C or C++ (or ASM, JAVA...), you will run into many problems with your apps and/or write horrible, backwards, slow code to do simple things.
So my suggestion: Before you learn VB, learn C (or C++, but C is simpler. If you want to learn OOP, then C++ or JAVA is good). You will realize in the long run that it will help you no matter what you program in. Try it. Not because I do it, but because you might find it useful.
Of course, that's just my opinion, I could be wrong  .
-
Aug 20th, 2001, 01:36 PM
#10
o, and btw, they're braces, not brackets
-
Aug 20th, 2001, 01:59 PM
#11
transcendental analytic
I've always known them as brackets somehow well 
My worst mistake was learning Gwbasic as my first language, i had a look at some of my apps made in it (thats about 8 years ago) and they just makes you sick, I'll post something and you'll see
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Aug 20th, 2001, 02:00 PM
#12
Member
Originally posted by chrisjk
Perl rules!
No interpreted language can rule.
-
Aug 20th, 2001, 02:01 PM
#13
Member
[] Brackets
() Parenthesis
{} Braces
-
Aug 20th, 2001, 02:43 PM
#14
PowerPoster
Originally posted by filburt1
No interpreted language can rule.
Yes it can, and it does.
-
Aug 20th, 2001, 02:44 PM
#15
PowerPoster
Originally posted by filburt1
[] Brackets
() Parenthesis
{} Braces
Or just to make it confusing...
[] Square brackets
() Brackets
{} Braces
-
Aug 20th, 2001, 02:49 PM
#16
Frenzied Member
Originally posted by filburt1
No interpreted language can rule.
It can. It does. And you can compile to a stand alone executable if you really want to.
Travis, Kung Foo Journeyman
As always, RTFM.
WWW Standards: HTML 4.01, CSS Level 2, ECMA 262 Bindings to DOM Level 1, JavaScript 1.3 Guide and Reference
Perl: Learn Perl, Llama, Camel, Cookbook, Perl Monks, Perl Mongers, O'Reilly's Perl.com, ActiveState, CPAN, TPJ, and use Perl;
YBMS, but Mozilla doesn't.
-
Aug 20th, 2001, 03:30 PM
#17
Thread Starter
New Member
Wow thanks for the quick responses people. Okay now how do I respond to all comments made. I know will take it in the order that the replies came.
Alright CyberTHug, A long while ago I grabbed a Microsoft C book and learnt quite a lot of theoretical C. I never intended to write any code, I just wanted to be able to understand all the applications I see coz most of them are written in C/C++.
I realise Dennis Ritchie and Ken Thompson guys were people who wrote operating systems and were hardcore programmers. They were working on PDP's , I think it was a PDP 7 then an 11 I dont quite remember. I know why C is so cudly. On the PDP's they didnt have the sort of memory we have today, our juicy 128 MB super dupa RAM. They couldnt afford to have lots and lots of lines of code coz memory was scarce, hence things like "int myInt" and not "Dim myInt as Integer". But what I now realise is we have chunks of memory to play with. Okay I am a performance freak and wont fool around with resources but it does mean that todays languages can handle the extra words that make the code readable. How about this. Out of all the words in the Ciyana declaration below you only have to type the name:
Reserve Integer StorageFor myInt
How? simple since these days everything nearly runs in an IDE we can have dialogs which you fill in. In the above case you select the data type and type the name then the rest is added for you. Now this may use more resources I admit but it could be feasible. VB and VC++ actually have Intellisense right? you type some it types the rest. Whats your view? Do you find it easier to type it all or do you prefer the autocomplete? I know some people can type like madmen/women (cant be sexist now can we)
but you gotta think about things like strain injury and the likes. You see I want to address such issues as well. For example in Ciyana i intended to use [] instead of () for my routines and arrays. So the snippet I gave before should have been: (note I didnt specify the return type b4 oops!!)
Public Integer Function[]
// blah blah
End Function
Why on earth am I doing that? Notice typing [] requires no shift while () actually do. When typing these I have to hold the shift key with my small finger and stretch up to the numbers (pretty tiresome if you are coding the whole day). Everyone what do you think of this? Good idea or is there some hidden fact about the ()?
By the way those operators ++, -- etc are actually in VB.NET......FINALLY. I agree with you they are pretty cool and Ciyana definitely will have them.
Hey guys what do you think about the == and =. Should Ciyana have them that way where the equality operator and assignment operator are different or should I take the VB approach and just use = for both?
Now Cyberthug, whats [b]scoping[b] I've never seen that before help me out here.
Okay now malloc and pointers. Oh by the way Ciyana is actually a language for sysytems programming so this sorta thing will be there for sure. Here is how malloc is implemented in Ciyana:
Get Byte[ byte count] StorageFor MyPointer.
I wanted the variable declarations and pointer declarations to be similar except for the Reserve (done at compile time ) and the Get (done at runtime) words. Releasing memory is just giving back memory to the OS which is what you are doing when you use delete[] myPointer in C++ (the square bracket thing some book said its always a good idea to include them so destructors for objects are called or something like that). Ciyana does it as follows. Since you Get memory and use it, when you are done you:
GiveBack StorageFor myPointer // where GiveBack is a keyword
I havent figured out a clean way to dereference them yet and I am still thinking whether C/C++'s method is cool, any ideas ?
Next, the :
for(t = 0, x = 0, y = 0; y < 100; ) { x = t++ * 2; y+=x;}
When compared to VB this structure is shining bright in terms of being to the point. Question for those of you who have had to maintain C/c++ programs. How do you fare with such conciseness when its been months after you wrote the code or are maintaining someone else's code ( the worst nightmare at times)?
VB is somewhat long winded but a possible though longer equivalent is:
t=0 : x = 0
for y = 0 to 99
x= t * 2 : t = t + 1 : y = y + x
' in VB.NET we will have ability to do this:
x = t * 2: t++ : y+=x
next
That cool for loop structure, I am thinking of modifying it slighltly for Ciyana purposes so I will get back to you when I do.
Now another thing I dont understand. When code is compiled be it written in C, Perl , Java or even Ciyana( when it comes out), it all ends up in some form of machine language (for compiled languages ) or some other intermediate form (for things like Perl).
So why on earth has VB got memory problems etc when ultimately, it ends up looking just like a C application when in binary. Is it the compiler or the language that has the problem? And if its the language, how can lines of text cause memory problems? Someone educate me here, theres something I am missing here. And since I want Ciyana to perform well, what am I meant to do to avoid those scoping problems n all?
Hey CyberThug, well spotted for the Join function. BUT ONE THING IS FOR SURE OBJECTIVE ONE OF CIYANA IS FULFILLED. ITS EASY TO UNDERSTAND, NOBODY EXPLAINED IT AND YOU GUYS PICKED IT ALL UP. Ofcourse thats just hello world but the rest is even better.
OOPS I GOTTA GO THEY ARE CLOSING DOWN AGAIN ( I AM AT WORK THIS TIME) I'll be back again on Tuesday. Thanks people and please lets keep talking. See ya, Eric.
-
Aug 21st, 2001, 04:58 AM
#18
Hyperactive Member
Originally posted by chrisjk
Or just to make it confusing...
[] Square brackets
() Brackets
{} Braces
Or how about.....
[] square brackets
() round brackets
{} curly brackets
-
Aug 21st, 2001, 05:06 AM
#19
Hyperactive Member
Oh BTW, I hate to admit it, but the debate about the names of these things ({[ ]}) was the only part of this thread I understood!
-
Aug 21st, 2001, 05:39 AM
#20
transcendental analytic
Originally posted by ericmuttta
[B]
Public Integer Function[]
// blah blah
End Function
Why on earth am I doing that? Notice typing [] requires no shift while () actually do. When typing these I have to hold the shift key with my small finger and stretch up to the numbers (pretty tiresome if you are coding the whole day). Everyone what do you think of this? Good idea or is there some hidden fact about the ()?
I have to press alt gr to access my []'s. I don't care about the parentesis and brackets, my fingers are used to all combinations on the keyboard so they never complain. I never think about where my keys are, there's probably a part of my brain that does that automatically.
By the way those operators ++, -- etc are actually in VB.NET......FINALLY. I agree with you they are pretty cool and Ciyana definitely will have them.
Hey guys what do you think about the == and =. Should Ciyana have them that way where the equality operator and assignment operator are different or should I take the VB approach and just use = for both?
I don't use C++ or any other language for that sake, I haven't seen everything in VB.NET but I think VB's original nature makes ++ and -- pre and postfix operators pretty useless. There's a wide range of statements but does that beat C++ that has only one and perfect type of statement? No way.
Now Cyberthug, whats [b]scoping[b] I've never seen that before help me out here.
Go learn C++ fully, with everything that comes with OOP, take a look at templates at the end and you'll be convinced (that is if you understand what you can do with C++) that there's no need for a Ciyana.
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Aug 21st, 2001, 08:33 AM
#21
Frenzied Member
Okay, a couple of points:
Don't worry about the keyboard. Some of use don't want to use QWERTY boards anyway.
Don't worry about the IDE. Any language that was written to work well in an IDE is crap. The language should have it's own merits. The IDE is just icing. Besides, I don't like using VS.
Scoping: Here are two blocks of code
VBScript
Code:
if (myTest) then
dim myVar
myVar = "Hello, World."
end if
myOutput myVar
PerlScript
Code:
my $Var;
if (myTest) {
$Var = "Hello, World."
}
myOutput($Var);
Notice how I declared myVar inside the if block in VBScript. If I had done the same thing in PerlScript and declared $Var inside the if block, then I would not be able to access it later outside of that block.
Scoping is the set of rules that affect the lifespan and visibility of a variable. In VB if you give a variable Global scope, then it can be seen everywhere (and you have just broken the second law of good programming).
VB's scoping is poor. I should be able to declare local variables inside a block and use them in that block and not have to worry about a conflict outside of that block. That is the way I preffer. VB doesn't seem to set any scoping smaller than a function/sub.
Also, it is Ciber with an I.
Travis, Kung Foo Journeyman
As always, RTFM.
WWW Standards: HTML 4.01, CSS Level 2, ECMA 262 Bindings to DOM Level 1, JavaScript 1.3 Guide and Reference
Perl: Learn Perl, Llama, Camel, Cookbook, Perl Monks, Perl Mongers, O'Reilly's Perl.com, ActiveState, CPAN, TPJ, and use Perl;
YBMS, but Mozilla doesn't.
-
Aug 21st, 2001, 09:50 AM
#22
Fanatic Member
i just finished learning pointers in C++...but
whats the point of pointer?
why point to the memory address of a variable when you can do
var1 = var2;
instead of
int *var1;
int *var2 = new int;
*var2 = 3;
*var1 = &var2;
(i think thats how you do it..im prolly wrong..correct me)
---
also in vb, i think instead of "dim"ing within a sub, if you do "private", that var will only be within that sub..im not too sure hto..
Last edited by nabeels786; Aug 21st, 2001 at 09:55 AM.
Visit www.fragblast.com
Gaming, forums, and a online RPG/Battle system
(__Flagg) DOT NET? is this a Hindi Dating service?
-
Aug 21st, 2001, 09:57 AM
#23
Pointers are very useful for manipulating strings and arrays. Also, what if a function needs to directly modify a value? C/C++ allow you to refer to the value of a pointer variable wth an asterisk and the address of a variable with an ampersand.
Additionally, C allows nested pointers, where **p would be a pointer to a pointer. This way, you can manipulate multi-dimentional arrays in the most powerful way.
In my opinion, anyone who has not learned how to use pointers, is limited in his programming potentials no matter what language he uses
Of course, that's just my opinion, I could be wrong.
-
Aug 21st, 2001, 10:05 AM
#24
Frenzied Member
Pointers
There are two reasons (that I can think of off the top of my head):
Number 1: And I don't use this very often if at all.
If you set myPtr to myVar, then if the value of myVar ever changes, the value retreived by myPtr will have changed. That way you don't have to keep reassigning variables. And the pointer will point to that memory, even when the variable for whom that memory has been reserved has gone out of scope.
Number 2: Lists
The simpliest is:
Code:
struct {
myInt;
myPrev;
myNext;
}
I can make a double linked list with pointers. I can then splice and join like an array, but I can make that struct as big as I want. I can start to make binary search trees, and it goes on from there.
Right now I'm using this in a PerlScript ASP:
Code:
$RS = $dbConn->Execute("$SQL");
while ($RS && !$RS->{EOF}) {
$deparmentID = $RS->Fields(0)->{Value};
$departments{$deparmentID} = [];
$departments{$deparmentID}->[0] = new TALLY;
$departments{$deparmentID}->[0]->{Name} = $RS->Fields(1)->{Value};
$RS->MoveNext();
}
$departments{} is a hash (%departments), or associative array. It has key/value pairs. The keys in this case are department IDs. The values are anonymous arrays. I'm pointing to the array. The first position in the array (index 0) is pointing, in turn, to a struct called TALLY, which has a scalar variable called Name.
Mind you I don't like that set up to terribly much, but it was quick and works. To do that without pointers requires huge freakin multideminsional arrays that have to be ReDim'ed and Preserved every time I want to add a new department.
Travis, Kung Foo Journeyman
As always, RTFM.
WWW Standards: HTML 4.01, CSS Level 2, ECMA 262 Bindings to DOM Level 1, JavaScript 1.3 Guide and Reference
Perl: Learn Perl, Llama, Camel, Cookbook, Perl Monks, Perl Mongers, O'Reilly's Perl.com, ActiveState, CPAN, TPJ, and use Perl;
YBMS, but Mozilla doesn't.
-
Aug 21st, 2001, 10:07 AM
#25
Frenzied Member
Originally posted by spetnik
In my opinion, anyone who has not learned how to use pointers, is limited in his programming potentials no matter what language he uses
Amen.
Travis, Kung Foo Journeyman
As always, RTFM.
WWW Standards: HTML 4.01, CSS Level 2, ECMA 262 Bindings to DOM Level 1, JavaScript 1.3 Guide and Reference
Perl: Learn Perl, Llama, Camel, Cookbook, Perl Monks, Perl Mongers, O'Reilly's Perl.com, ActiveState, CPAN, TPJ, and use Perl;
YBMS, but Mozilla doesn't.
-
Aug 21st, 2001, 10:08 AM
#26
Member
Pointers calls general protection faults and security violations. That's why they're not explicitly implemented in Java. In Java, practically everything is a pointer, but you don't declare them that way and you have no way of knowing where in memory the pointer refers to.
-
Aug 21st, 2001, 10:10 AM
#27
If you use them correctly pointers will not "call general protection faults and security violations".
-
Aug 21st, 2001, 10:19 AM
#28
Frenzied Member
Exactly Dennis. They are called memory leaks, too, Fil.
Java uses pointers for everything because it is meant to be implemented on various platforms. Those platforms will have very different mechanisms that Java is trying to hide from you, keep transparent. You have a set uniform front end, and the Java engine has to deal with the various memory management techniques that can be implemented on different platforms.
Travis, Kung Foo Journeyman
As always, RTFM.
WWW Standards: HTML 4.01, CSS Level 2, ECMA 262 Bindings to DOM Level 1, JavaScript 1.3 Guide and Reference
Perl: Learn Perl, Llama, Camel, Cookbook, Perl Monks, Perl Mongers, O'Reilly's Perl.com, ActiveState, CPAN, TPJ, and use Perl;
YBMS, but Mozilla doesn't.
-
Aug 21st, 2001, 11:18 AM
#29
transcendental analytic
Originally posted by CiberTHuG
Exactly Dennis. They are called memory leaks, too, Fil.
Memory leaks occurs when allocated memory on the heap is not deallocated where it should be.
The real power of pointers are pointer aritmetics, not the access they provide, as languages with hided pointers do that anyway, but instead disallows any pointeraritmetics which is mainly a big source of programming faults, but all lowlevel operations are such by nature.
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Aug 21st, 2001, 11:28 AM
#30
Frenzied Member
I was thinking memory leak as in...
If you have a memory space (say 4 bytes) reserved and you have a pointer to it. If you write 5 bytes of data to that address, you will write over top of whatever comes after. As long as the next byte is still part of the same program, the OS should let you do that. The OS should keep you from access the memory block of another program (access violation).
Perhaps leak is not the correct term, but anyway. I know it is not an overflow/underflow problem. That is floating point.
I've never used pointer arithmetic. I've never had a need to. The closest I've come is some assembly work with offsets. I'm sure its fun, though.
Travis, Kung Foo Journeyman
As always, RTFM.
WWW Standards: HTML 4.01, CSS Level 2, ECMA 262 Bindings to DOM Level 1, JavaScript 1.3 Guide and Reference
Perl: Learn Perl, Llama, Camel, Cookbook, Perl Monks, Perl Mongers, O'Reilly's Perl.com, ActiveState, CPAN, TPJ, and use Perl;
YBMS, but Mozilla doesn't.
-
Aug 21st, 2001, 11:43 AM
#31
transcendental analytic
ooh you're missing something big Pointeres are not there to look fancy, there's a reason and that's pointer artimetics. Otherways you could go switch over to Java or something less dangerous. It takes care of all memory allocation/deallocation and pointers.
I think the problem is called fence post error, but i'm not quite sure if it's generally for all kind of operations on unallocated data on the heap.
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Aug 21st, 2001, 01:46 PM
#32
Frenzied Member
VB also doesn't short circuit. I just rediscovered that. *grumble*
Travis, Kung Foo Journeyman
As always, RTFM.
WWW Standards: HTML 4.01, CSS Level 2, ECMA 262 Bindings to DOM Level 1, JavaScript 1.3 Guide and Reference
Perl: Learn Perl, Llama, Camel, Cookbook, Perl Monks, Perl Mongers, O'Reilly's Perl.com, ActiveState, CPAN, TPJ, and use Perl;
YBMS, but Mozilla doesn't.
-
Aug 21st, 2001, 02:11 PM
#33
transcendental analytic
not to induce confusion among the simpleminded
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Aug 21st, 2001, 02:57 PM
#34
Thread Starter
New Member
Hey people I am back!!!!
Now whats going on here, everyone is talking about pointers all of a sudden. Nobody said why C++ is more efficient than say VB or any other language for that matter, when ultimately after compilation they are all binary code. So is it the language or the actual compiler that leads to the efficiency?....somebody please help me out here.
Okay about the bracket/brace/whatever thing, I'll skip that I had forgotten that keyboards vary across the world.
As for the ++ and -- operator, in VB they are only useful for stuff like: a= a +1 within loops. For Ciyana, i intended to limit them to that very purpose. In C++, I have seen pointer arithmetic, function calls etc using this eg myFn(i++) .Now thats alright but problems can arise with that sort of thing when macros show up:
Woops gotta go, we'll be back to show you what i mean with the macros.
-
Aug 21st, 2001, 02:59 PM
#35
Member
Originally posted by ericmuttta
As for the ++ and -- operator, in VB they are only useful for stuff like: a= a +1 within loops. For Ciyana, i intended to limit them to that very purpose. In C++, I have seen pointer arithmetic, function calls etc using this eg myFn(i++) .Now thats alright but problems can arise with that sort of thing when macros show up:
Are you kidding? I use ++ and -- all the time and wish that VB.NET would have them! And you can use += in string concatenations.
And me hate pointers.
-
Aug 21st, 2001, 03:05 PM
#36
Monday Morning Lunatic
Macros are evil, use inline functions instead Same effect and the code is no slower, but it's safer
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Aug 21st, 2001, 03:08 PM
#37
Member
This is my favorite macro definition set:
Code:
#define bool int
#define true 1
#define false 0
No more including bool.h for older C++ libraries!
-
Aug 21st, 2001, 03:09 PM
#38
PowerPoster
-
Aug 21st, 2001, 03:09 PM
#39
Member
And this:
Code:
#pragma message Your code is evil and bad
That makes the compilter give you an error or warning that says "Your code is evil and bad"
-
Aug 21st, 2001, 03:12 PM
#40
Frenzied Member
Pointers are good.
Okay, why is C++ more efficent than VB.
Okay... memory use. VB uses more memory than C++. If you ask for a String in VB, you are sucking up memory. In C++ I can char* and get just what I need.
I would say write a simple algorithm in both VC++ and VB, and then disassemble them. Look at them. We can suggest code to use if you would like. Perhaps the Towers of Hanoi. But I think you will see streamlining in the VC++ executable that you won't see in the VB.
Travis, Kung Foo Journeyman
As always, RTFM.
WWW Standards: HTML 4.01, CSS Level 2, ECMA 262 Bindings to DOM Level 1, JavaScript 1.3 Guide and Reference
Perl: Learn Perl, Llama, Camel, Cookbook, Perl Monks, Perl Mongers, O'Reilly's Perl.com, ActiveState, CPAN, TPJ, and use Perl;
YBMS, but Mozilla doesn't.
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
|
Click Here to Expand Forum to Full Width
|