Hello ! I have a problem which I can't resolve. I wrote program for 89C2051 for one of my friend in Basom Basic compiler (http://www.mcselec.com). Compiled code was about 1945 bytes. Since I prefer C, I transalte Bascom basic to C. But when I compile, generated code was 2313. I try to change optimization parameters, but generated code never go below 2313. Even bigger. Where am I wrong ? Is it possible that stupid Basic make smaller code tne best C compiler ? Then I find out that this code: while (1) { printf ("Hello World\n"); } generate fully 1093 bytes (!) for Atmel 89C2051. 1093 bytes???? Three lines? Same program in Bascom generate only 154 (!) bytes. When I remove all "printf" from my C code, generated code was arond 2200 byte. But, with same action in Basic code (remove all "print") 1340 bytes long code. Exactly same program in Keil C and Bascom basic generate 860 byte smaller code ! I don't belive this. Do I have to program in (stupid) Basic if I want smaller code ? I still belive I did mistake somewhere, so I need help. I will send both C and basic code for interested people. With best regards !
"The REAL problem with C and more so with C++ is that it allow the programmer to obfusciate the code to a level where no single soul can figure out what happens" Oh yes - this is definitely true. However, I can't see that the same is any less true in Assembler. I think the problem here lies in the programmers - not the language?! Of course you are right; however obfusciated assembler is a lot easier to decipher than morphed, encapsulated and whatever C++. The point I am making is that the more "abstract" the language allow you to be, the easier it is to hide what it is you are doing (just compare an abstract painting to a naturalistic). Thus a C++ programmer has to be extremely conscious of the maintainability of his/her code more so that utilizing all bells and whistles the language allow and I have yet to see C++ code written expressly for maintainability. Show me that a majority of C++ programmers are writing code expressly for maintainability (no babble about safety from encapsulation and all that other hype) and I may change my attitude about that language. Erik
"Of course you are right; however obfusciated assembler is a lot easier to decipher than morphed, encapsulated and whatever C++." Not for those of us who are used to using these new-fangled high level language things! "The point I am making is that the more "abstract" the language allow you to be, the easier it is to hide what it is you are doing" Exactly! "Thus a C++ programmer has to be extremely conscious of the maintainability of his/her code" Maintainability is one of the strong points of C++. I'd say that well written assembler is more difficult to maintain than poorly written C++. As an amusing excercise try translating a few lines of an assembler program as directly as possible into C on a line by line basis. Once you remember what a lovely and incredibly useful keyword 'goto' is you'll make progress. "Show me that a majority of C++ programmers are writing code expressly for maintainability" Of course they aren't, they're writing code to produce a working product. Maintainability is just one of the many side benefits of using C++. "(no babble about safety from encapsulation and all that other hype) and I may change my attitude about that language" You can't expect us to expalin the benefits of a language with the proviso that we ignore the features that provide the benefits! Erik, you just seem to think that your way is the only way, and you're going to hang on to it at any cost. Good luck! Stefan
"(no babble about safety from encapsulation and all that other hype) and I may change my attitude about that language" You can't expect us to explain the benefits of a language with the proviso that we ignore the features that provide the benefits! Stefan, the features babbled about serves only to hide what you are doing which hardly improves maintainability. The claim that "abstraction" improves maintainability is pure unadulterated bs. Anyhow since there are three things you can not discuss with your barber: religion, politics and taste this will lead nowhere. I offered you a way to convince me: "show me that a majority of C++ programmers write for maintainability" and insted of replying to that you babble about "automatic maintainability" which is impossible. My main objection to C++ is not the language, but the way it is treated. When assembler is taught every other sentence is "think mainatinability" when C++ is taught every other sentence is "the language takes care of that". My problem with C++ is not as much with the language as the way it is taught "everything will be better when you use C++" which is a load of compost. I once employed a C programmer who when asked to put commets in his code and break up some mile long statements answered "that is not real C". This attitude is so much more prevalent in C++ programmers. The fact that C++ provides an excuse to write unmaintainable code because it claims that it (just read your own statements) makes the code maintainable is the worst thing possible. Erik
"(no babble about safety from encapsulation ... the features babbled about serves only to hide what you are doing which hardly improves maintainability." Erik, 'encapsulation' doesn't mean hiding what you are doing. Quite the opposite - it makes clear what you are doing. "I offered you a way to convince me: "show me that a majority of C++ programmers write for maintainability" and insted of replying to that you babble about "automatic maintainability" which is impossible." I'm afraid you've imagined my use of the word 'automatic'. By the way, I wasn't babbling. "when C++ is taught every other sentence is "the language takes care of that"" No professional teacher would say that. Neither do any of my C++ books. Did your teacher say that? Ahh.. you've never been taught C++. "I once employed a C programmer who when asked to put commets in his code and break up some mile long statements answered "that is not real C"" Well, there are always a few bad eggs. I've worked with a couple of individuals who took this sort of attitude however their real intention was to, and I quote, 'keep the amateurs out'. The language used was irrelevant - nothing was commented. "The fact that C++ provides an excuse to write unmaintainable code because it claims that it (just read your own statements) makes the code maintainable is the worst thing possible." C++ doesn't provide an excuse to write unmaintainable code. It does however aid writing maintainable code. I think it is obvious (and I've never tried to suggest otherwise) that this requires some effort from the programmer. Stefan
Stefan, 1) Did you read the interview with Bjarne I posted the link to? There is the real truth. 2) I have nothing against any language when applied in the places where it belong, my hair raise when someone states that it is the right choice in all situations. 3) C++ (at least in its present form) has no place in the '51 world, if you want to use it on a PC be my guest. Erik
Erik, 1) Sure, that's been on the go for years. Bjarne claims it would have been funnier if he'd written it but I doubt that somehow. 2) Indeed. However, I feel the same way when someone states that something is the wrong choice in all situations because that is equally false. 3) I do use C++ on the PC and I don't use C++ on the 8051. However, I also use C and very rarely assembler on the PC, and I would be interested to try the C++ implementation on the 8051. Tell me, have you actually tried it? If not, have you read any report by anyone who has actually tried it? Stefan
C++ compilers are very useful for embedded design. This is true even if you write using only C constructs. The primary benefit I find is that they can help remove type errors not caught by C compilers. When selecting a language and compiler, you need to weigh the cost of the options afforded you.