kevin@cbmvax.UUCP (Kevin Klop) (07/03/89)
BTW, the construct: int a[] = {1, 2, 3}; usually doesn't create any code (unless the intialization is allowed for autovariables). Instead it merely places the values into the initialized data segment instead of zeros. for instance, the above might generate the follwoing assembly code: section BSS global a a: db.w 1 db.w 2 db.w 3 whereas the equivalent M2 code: a : array [0..2] of integer; a[0] := 1; a[1] := 2; a[2] := 3; would generate something along the lines of: section text movea a7,a0 adda #6,a7 moveq.w #1,0(A0) moveq.w #2,2(A0) moveq.w #3,4(A0) Note that this does not prove one superior over the other. They are different, and have different strengths and weaknesses. In this particular case, C comes out as generating 6 bytes into the data segment, and M2 comes out as generating 14 bytes into the code segment. (If M2 doesn't allocate the variable on the stack, then 2 bytes of code space are recovered). To handle nested routines, the only "special" coding necessary is to keep track of the current stack frame pointer. This CAN be a pain in the neck, agreed, as when accessing a variable one has to check backwards from the current stack frame throught the next higher nesting level stack frame. Yet, there ARE advantages to it. Ah well, I said that I didn't want to get involved in a "Language X is better that language Y" discussion, and here I am starting to think about it. *grin* -- Kevin -- Kevin Klop {uunet|rutgers|amiga}!cbmvax!kevin Commodore-Amiga, Inc. The number, 111-111-1111 has been changed. The new number is: 134-253-2452-243556-678893-3567875645434-4456789432576-385972 Disclaimer: _I_ don't know what I said, much less my employer.
charles@hpcvca.CV.HP.COM (Charles Brown) (07/06/89)
> BTW, the construct: > int a[] = {1, 2, 3}; > usually doesn't create any code (unless the intialization is allowed for > autovariables). Instead it merely places the values into the > initialized data segment instead of zeros. > whereas the equivalent M2 code: > a : array [0..2] of integer; > a[0] := 1; a[1] := 2; a[2] := 3; Pphhttt!!! This is not equivalent code. The equivalent code in C is: int a[3]; a[0] = 1; a[1] = 2; a[2] = 3; So for this example C is capable of doing exactly what M2 is doing, but M2 is not able to do what C is capable of. > Note that this does not prove one superior over the other. They are > different, and have different strengths and weaknesses. ... THIS example in fact DOES show one superiority of C. > Ah well, I said that I didn't want to get involved in a "Language X is better > that language Y" discussion, and here I am starting to think about it. *grin* > Kevin Klop {uunet|rutgers|amiga}!cbmvax!kevin You chose a poor example to avoid THAT arguement. -- Charles Brown charles@cv.hp.com or charles%hpcvca@hplabs.hp.com or hplabs!hpcvca!charles or "Hey you!" Not representing my employer. "The guy sure looks like plant food to me." Little Shop of Horror