flat assembler
Message board for the users of flat assembler.

Index > High Level Languages > C++ or ASM

Goto page Previous  1, 2, 3, 4, 5  Next
Author
Thread Post new topic Reply to topic
okasvi



Joined: 18 Aug 2005
Posts: 382
Location: Finland
okasvi 25 Jul 2006, 00:10
I'd like to see C(not C++) that uses fasm as backend and has samekind of design principles or atleast allows fasm to be used in __asm{}.


edit: even if it would compile for just ia32
Post 25 Jul 2006, 00:10
View user's profile Send private message MSN Messenger Reply with quote
kohlrak



Joined: 21 Jul 2006
Posts: 1421
Location: Uncle Sam's Pad
kohlrak 25 Jul 2006, 00:50
What i'd like to see would be competition for java and flash. Something in Assembly that works like java or flash, only since the targets will be for performance and cross compatability, it should be better than something that just targets portability.
Post 25 Jul 2006, 00:50
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3170
Location: Denmark
f0dder 25 Jul 2006, 11:41
kohlrak wrote:
Quote:
C++ is a multiparadigm language; you can write procedural code, object-oriented code, template metaprogramming code... it's speed depends on the code you write (and the compiler), nothing about C++ makes it automatically slower than C.


Correct, but when you learn C++, most of the time thy don't tell you about printf over cout << or any other C equivalents, they just tell you the C++'s standard library (even though it's not part of the C++ language, and is only included with almost every compiler). That's the problem, they teach you the slow stuff... It was only by a random topic i found in another community that told me that the C equivalents were faster and that there even were any.


If you worry about formatted I/O speed, either you're doing very simplistic stuff or you're worrying too much. Only in a few special cases does this really matter. I'm not too much of a fan of C++ iostreams because on many implementations, for the smallish projects I do most of, they pull in too much functionality - including the not-so-useful localization stuff.

There's a bunch of advantages to them, though. Compile-time type safety. Centralized formatter support. Extensibility (how would you add arbitrary object printing to printf()?), etc.

C++'s standard library is as much a part of the language as libc is part of the C language.

kohlrak wrote:

Quote:
Nor more secure, really, if you still use libc.


I'm not sure how it works, but sometimes in C, you can make calls to functions and not fill all the parameters. It's this assembly too, not all macros or functions have to have their parameters filled. The alert boxes come to mind.

That's doable in C++ as well - the "ellipsis argument list", like void foo(char* output, ...);, and then use of <stdarg.h>:va_start,va_arg,va_end to process. There's often cleaner ways to do stuff in C++, though.

kohlrak wrote:

That makes C++ a little easier to debug than C or assembly, which shouldn't really matter to the perfect coder, but everyone makes mistakes. Here's a tip for your friends though, make them learn assembly, cause you won't beleive how much un-worth it, it really is.

What makes it easier? I can't quite follow you here. Your last sentence doesn't make much sense either.

kohlrak wrote:

Something i saw from a web page i'm learning Assembly off of. And it's very true that how many people who know C++ or such Curse at assembly. Why? the time consuming thing. I'm not kidding you, a C++ teacher at my school said he saw his friend coding in assembly and he thought it was crazy or insane.


A person attempting anything large in assembly, especially if it's teamwork, is a bit crazy Smile - there just isn't any reason to do so.

Playing a bit on the large blob of text you quoted, I could add the following...
Speed is probably the biggest complaint 1337 Asm0rs have against High-Level Languages. They refuse HLLs because it's slow and bloated, and then they turn around and write even slower code in assembly. - ^_^. My "bin2obj" program is written in C++ (yes, using objects) and the exe is still just 4kb. Bloat?

_________________
Image - carpe noctem
Post 25 Jul 2006, 11:41
View user's profile Send private message Visit poster's website Reply with quote
Patrick_



Joined: 11 Mar 2006
Posts: 53
Location: 127.0.0.1
Patrick_ 25 Jul 2006, 14:34
Again, it all goes back to choosing the right tool for the job. Sometimes a high-level language will be more practical for your project.

What I really don't like is people bashing things they don't know much about. For example, a C++-only coder, who thinks any non-OO language is a waste of time, and assembly is worthless. It's good to know at _least_ a little about a lot. Knowing a very low level language (asm) can be _extremely_ beneficial.

In fact, by learning and using assembly to program, I've learned more about how my hardware works, and programming, and I believe I've become a better programmer in general because of it.
Post 25 Jul 2006, 14:34
View user's profile Send private message Reply with quote
kohlrak



Joined: 21 Jul 2006
Posts: 1421
Location: Uncle Sam's Pad
kohlrak 25 Jul 2006, 18:13
kohlrak wrote:

Quote:
Nor more secure, really, if you still use libc.


I'm not sure how it works, but sometimes in C, you can make calls to functions and not fill all the parameters. It's this assembly too, not all macros or functions have to have their parameters filled. The alert boxes come to mind.

That's doable in C++ as well - the "ellipsis argument list", like void foo(char* output, ...);, and then use of <stdarg.h>:va_start,va_arg,va_end to process. There's often cleaner ways to do stuff in C++, though.

Code:
void function(int a, int b){
//Pretend code is here...
return; }

void main(){
function(2);
return; }    


I was told that code would compile in C, and i know for a fact it won't compile in C++. And incase you're about to ask me then how printf works...?

Code:
exturn "C"    


Sometimes works, not to forget that you can overload functions too.

Quote:
In fact, by learning and using assembly to program, I've learned more about how my hardware works, and programming, and I believe I've become a better programmer in general because of it.


And so have i, but i knew a slight bit from C++ coding on certain community forums. None of them knew assembly but a few correct rumors about assembly were passed about... Only a few though... the rest were just bashing assembly, and i'm sick of it. lol
Post 25 Jul 2006, 18:13
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger Reply with quote
okasvi



Joined: 18 Aug 2005
Posts: 382
Location: Finland
okasvi 25 Jul 2006, 18:56
kohlrak wrote:
Code:
exturn "C"    


Sometimes works


I believe it's 'extern'.

_________________
When We Ride On Our Enemies
support reverse smileys |:
Post 25 Jul 2006, 18:56
View user's profile Send private message MSN Messenger Reply with quote
kohlrak



Joined: 21 Jul 2006
Posts: 1421
Location: Uncle Sam's Pad
kohlrak 25 Jul 2006, 19:06
I never spell it right because i never use it. lol
Post 25 Jul 2006, 19:06
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger Reply with quote
rugxulo



Joined: 09 Aug 2005
Posts: 2341
Location: Usono (aka, USA)
rugxulo 26 Jul 2006, 03:36
Does Context count? It's similar to C, kinda sorta. Smile

okasvi wrote:
I'd like to see C(not C++) that uses fasm as backend and has samekind of design principles or atleast allows fasm to be used in __asm{}.


edit: even if it would compile for just ia32
Post 26 Jul 2006, 03:36
View user's profile Send private message Visit poster's website Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3170
Location: Denmark
f0dder 26 Jul 2006, 08:29
kohlrak wrote:

Code:
void function(int a, int b){ 
//Pretend code is here... 
return; } 

void main(){ 
function(2); 
return; }
    


I was told that code would compile in C, and i know for a fact it won't compile in C++. And incase you're about to ask me then how printf works...?


That won't compile in any sane compiler. Also, "void main" is plain wrong and nonstandard, it's "int main()" - and you really ought to do "int main(int argc, char* argv[])".

How printf works? The definition is something like "int printf(char *fmt, ...);" - how it's implemented is up to the library writer, but probably with va_{start,arg,end} calls.
Post 26 Jul 2006, 08:29
View user's profile Send private message Visit poster's website Reply with quote
kohlrak



Joined: 21 Jul 2006
Posts: 1421
Location: Uncle Sam's Pad
kohlrak 26 Jul 2006, 19:49
void main() compiles in MSVC.
Post 26 Jul 2006, 19:49
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3170
Location: Denmark
f0dder 26 Jul 2006, 19:53
It might compile, but it's nonstandard. I can't see why it should cause problems anywhere, but it's bad karma to do...
Post 26 Jul 2006, 19:53
View user's profile Send private message Visit poster's website Reply with quote
kohlrak



Joined: 21 Jul 2006
Posts: 1421
Location: Uncle Sam's Pad
kohlrak 26 Jul 2006, 20:03
I prefer it.
Post 26 Jul 2006, 20:03
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger Reply with quote
okasvi



Joined: 18 Aug 2005
Posts: 382
Location: Finland
okasvi 26 Jul 2006, 21:10
rugxulo wrote:
Does Context count? It's similar to C, kinda sorta. Smile


Looks nice and ceeish Smile but I think I'll let it mature for while.

_________________
When We Ride On Our Enemies
support reverse smileys |:
Post 26 Jul 2006, 21:10
View user's profile Send private message MSN Messenger Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3170
Location: Denmark
f0dder 27 Jul 2006, 10:19
kohlrak wrote:
I prefer it.


Why? it's wrong...

Most C/C++ implementations return the value from main() to the operating system, which on many systems can be checked ("errorlevel" in dos). This is crucial for console mode apps of the type that can be used from shell scripts/batch files (ie., if the tool doesn't return 0, some error happened and we need to abort).

Using "void main" means whatever junk is present in EAX will be returned. Bad idea. A conforming C++ compiler actually ought to reject main() functions with a nonstandard signature.

For a C program, GCC warns about it (on the *default* warning level!), and for a C++ program it gives you an error.

MSVC doesn't warn or error on either, which is to be seen as a compiler bug.

_________________
Image - carpe noctem
Post 27 Jul 2006, 10:19
View user's profile Send private message Visit poster's website Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 27 Jul 2006, 12:18
it just mean your program DOESN'T return value. It same as stating that function declared as returning void is bug - it also leaves junk in EAX, which can be tested some way
Post 27 Jul 2006, 12:18
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3170
Location: Denmark
f0dder 27 Jul 2006, 15:06
vid wrote:
it just mean your program DOESN'T return value. It same as stating that function declared as returning void is bug - it also leaves junk in EAX, which can be tested some way


WRONG - main() is a special function, and the standard clearly says so. If "void main()" doesn't break on your system, that's just luck... or rather, it's bad, because it'll leave you to believe that it's okay code, and might then blow up in your face later.

(yes, the C standard allows for non-int main(), but the results are "undefined". The C++ standard explicitly requires int-main).

_________________
Image - carpe noctem
Post 27 Jul 2006, 15:06
View user's profile Send private message Visit poster's website Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 27 Jul 2006, 16:21
system doesn't care about return code of app - it's caller that does. same way as in functions.

what is reason to treat this one thing specially? if program doesn't have anything to return...
Post 27 Jul 2006, 16:21
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3170
Location: Denmark
f0dder 27 Jul 2006, 16:27
vid wrote:
system doesn't care about return code of app - it's caller that does. same way as in functions.


Sure... but if you use a tool from a makefile, you better damn be sure that it returns 0.

vid wrote:

what is reason to treat this one thing specially? if program doesn't have anything to return...

Why treat callbacks specially? If they don't have anything to return...

main() is called from an external source outside of your control (ie, the libc crt0 code) - so it's a no-brainer, really, that it should follow a standard signature. Try making it STDCALL, for instance.

Btw both GCC and VC2003 "xor eax, eax" if you don't return anything from main. For "int main" without a return statement this is standardized because it implicitly returns 0 then. For void main, this smells more like a fix for bad and broken code... any other void function does NOT have EAX cleared on exit.

_________________
Image - carpe noctem
Post 27 Jul 2006, 16:27
View user's profile Send private message Visit poster's website Reply with quote
kohlrak



Joined: 21 Jul 2006
Posts: 1421
Location: Uncle Sam's Pad
kohlrak 27 Jul 2006, 20:02
f0dder wrote:
vid wrote:
system doesn't care about return code of app - it's caller that does. same way as in functions.


Sure... but if you use a tool from a makefile, you better damn be sure that it returns 0.

vid wrote:

what is reason to treat this one thing specially? if program doesn't have anything to return...

Why treat callbacks specially? If they don't have anything to return...

main() is called from an external source outside of your control (ie, the libc crt0 code) - so it's a no-brainer, really, that it should follow a standard signature. Try making it STDCALL, for instance.

Btw both GCC and VC2003 "xor eax, eax" if you don't return anything from main. For "int main" without a return statement this is standardized because it implicitly returns 0 then. For void main, this smells more like a fix for bad and broken code... any other void function does NOT have EAX cleared on exit.


Therefor, the EAX goes back to what called the main function (opened the program). Simple enough, but the fact is. What does it do? Nothing... It is unused. If "the program crashes" it's the same as a program that "crashes" using "int" type. Theoretically, you could simply make main a bool value, but even that is not needed. It appears to me you care about int so much because it's part of "windows' troolean logic." Essentually, unless you call the program from a special CMD edit or such, the data isn't even looked at that i know of.
Post 27 Jul 2006, 20:02
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3170
Location: Denmark
f0dder 27 Jul 2006, 20:14
Whatever.

Seems like you like undefined behaviour, I don't.
Post 27 Jul 2006, 20:14
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page Previous  1, 2, 3, 4, 5  Next

< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2023, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.