flat assembler
Message board for the users of flat assembler.

Index > Heap > Learn C++?

Goto page Previous  1, 2, 3  Next
Author
Thread Post new topic Reply to topic
windwakr



Joined: 30 Jun 2004
Posts: 827
Location: Michigan, USA
windwakr
You know what? Screw high level languages! I'm gonna stick with good old assembly.

To me C and C++ are too complex to learn....probably the same thing a C/C++ coder would say about assembly.

I also like keeping COMPLETE control over my programs, and I HATE the bloat of HLL.

I compiled a simple program in C++ using release compile and everything and the .exe was around 50KB....the same thing in assembly would be around 5KB
Post 09 Nov 2008, 02:01
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr
windwakr,

That's the beauty of default runtime library: you get the features even when you don't need them, and there is no way to drop them. However, you may compile much simple startup module and link your program with it…
Post 09 Nov 2008, 09:38
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
Quote:
That's the beauty of default runtime library: you get the features even when you don't need them, and there is no way to drop them.

bullshit
Post 09 Nov 2008, 10:53
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr
vid,

OK, how will you get rid of unnecessary startup code in "Hello, Word!"? E.g. command line/environment parsing, heap management and such.

I was sarcastic about "the beauty".
Post 09 Nov 2008, 13:40
View user's profile Send private message Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3170
Location: Denmark
f0dder
Find the compiler/linker flag to disable default inclusion, and add your own PE entrypoint... then drop libc references. Not a hard thing to do, but it ever more irrelevant these days.
Post 09 Nov 2008, 15:05
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
baldr:

with MSVC it is something like following:
Code:
#include <windows.h>
void main()
{
  DWORD chars;
  HADNLE stdout = GetStdHandle(STD_OUTPUT_HANDLE);
  WriteConsoleA(stdout, "Hello World", 11, &chars, 0);
  ExitProcess(0);
}
    

compile with something like: (you need path to includes and libs set)
Code:
cl /c file.c
link /nodefaultlib /entry:main file.obj kernel32.lib
    


i am writing this just off memory, maybe i forgot something.
Post 09 Nov 2008, 15:35
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Borsuc



Joined: 29 Dec 2005
Posts: 2466
Location: Bucharest, Romania
Borsuc
Yeah you forgot something, you need mainCRTStartup (at least in my Visual Studio, too lazy to update) not just main Wink (and yeah I do that all the time in my C programs).

windwakr: IMO knowing a HLL that is low-level like C (compared to other HLL shit like Java or C#) is good practice, and that doesn't mean you have to scrap assembly at all. Even when programming in C I still think "in assembly" how it turns out, how an "if" is actually a conditional jump (and I also use goto frequently, trust me it's not spaghetti code because it doesn't jump back and forth), etc... It's useful to program in a HLL before assembly (that is, you first do it in C, and then in asm), most times this can be used:

1) for portability
2) for an "average" outline of the algorithm

If you want a quick outline, use comments with some pseudo-code Smile
Contrary to what most say, I find the most time-consuming process the thinking about the algorithm and making it optimized (the algorithm, not the low-level optimizations, though you still need to think in assembly and what operations are faster or whatever), not writing down the code, like what most people claim.

Remember to document your code and all "relationships" between files/functions (well maybe groups of functions). It's much easier for someone else and might be for you later. I know most people hate to do documentation but I find it extremely worth it, even for me, not only for "others". Wink

_________________
Previously known as The_Grey_Beast
Post 09 Nov 2008, 16:55
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr
vid,

I know how to do it manually. We're talking about windwakr's opinion to dump entire thing just for defaults being so clumsy, no?

Borsuc,

I agree, IMHO for pseudo-code C syntax is at least acceptable, if not useful. Most statements/operators will directly translate to underlying code (on the contrary, bswap is awful in most C implementations, Intel's intrinsics appears to be good solution).
Post 09 Nov 2008, 18:01
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
Quote:
Yeah you forgot something, you need mainCRTStartup (at least in my Visual Studio, too lazy to update) not just main (and yeah I do that all the time in my C programs).

No I don't. "mainCRTStartup" is defaut entry point, but i have overridden it with "/entry:main" switch.

Quote:
I know how to do it manually. We're talking about windwakr's opinion to dump entire thing just for defaults being so clumsy, no?
In that case your "there is no way to drop them" misled me. Anyway, I think windwakr didn't talk about just defaults, my opinion is he didn't know there is some else option.
Post 09 Nov 2008, 20:19
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr
vid,

By "no way to drop them" I meant something different: if no references to feature's usage, why include it's supporting code in runtime? Why do we have (almost) self-assembling IDT/IAT/ILT and don't have the same for start-up code?
Post 09 Nov 2008, 20:54
View user's profile Send private message Reply with quote
windwakr



Joined: 30 Jun 2004
Posts: 827
Location: Michigan, USA
windwakr
I've decided i'll take some time and learn C some day in the future, but for now I'm gonna focus on expanding my assembly knowledge.

_________________
----> * <---- My star, won HERE


Last edited by windwakr on 10 Nov 2008, 01:01; edited 1 time in total
Post 09 Nov 2008, 21:04
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr
windwakr,

That's right. Know your gear, it helps alot to step and even run! Wink

K&R C was supposed to be somewhat higher than assembler, but not much… Wink
Post 09 Nov 2008, 21:10
View user's profile Send private message Reply with quote
dap



Joined: 01 Dec 2007
Posts: 61
Location: Belgium
dap
windwakr wrote:
To me C and C++ are too complex to learn....probably the same thing a C/C++ coder would say about assembly.

C really is a difficult language, and C++ is even more complex. If you don't have any reason to learn C or C++ specifically I would recommend a more simple and consistent HLL such as Python.

windwakr wrote:
I compiled a simple program in C++ using release compile and everything and the .exe was around 50KB....the same thing in assembly would be around 5KB


http://msdn.microsoft.com/en-us/library/abx4dbyh(VS.80).aspx

_________________
(French only) http://dap.developpez.com
Post 11 Nov 2008, 16:26
View user's profile Send private message Visit poster's website Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr
dap,

FORTH is one of the most consistent languages ever ("everything is word"), but it's extensibility (state-aware words at most) made the dark deed… Wink
Post 11 Nov 2008, 18:49
View user's profile Send private message Reply with quote
Borsuc



Joined: 29 Dec 2005
Posts: 2466
Location: Bucharest, Romania
Borsuc
What's so hard about C? Confused

+, -, *, /, ^, &, | and a few other operators. Variables with a simple type, "=" sign to assign them (not := or other), simple blocks '{' and '}' used for stuff (many languages have some) or loops or ifs, without needing excessive english words like "then" just simple symbols...

then functions are intuitive too, only problem is pointers but you'll get used to it.
Post 13 Nov 2008, 17:15
View user's profile Send private message Reply with quote
drhowarddrfine



Joined: 10 Jul 2007
Posts: 535
drhowarddrfine
I don't think any asm programmer would have problems with pointers but trying to explain pointers to the compiler is a pita. I wish I had an example of the many heiroglyphs that must appear before a function just so the compiler knows the return value. Sometimes I find myself yelling at the screen "It's just a DWORD, stupid!!!".
Post 13 Nov 2008, 19:35
View user's profile Send private message Reply with quote
dap



Joined: 01 Dec 2007
Posts: 61
Location: Belgium
dap
Borsuc wrote:
What's so hard about C? Confused

+, -, *, /, ^, &, | and a few other operators. Variables with a simple type, "=" sign to assign them (not := or other), simple blocks '{' and '}' used for stuff (many languages have some) or loops or ifs, without needing excessive english words like "then" just simple symbols...

then functions are intuitive too, only problem is pointers but you'll get used to it.


  • The static and extern don't have the same meaning in different contexts
  • EOF doesn't mean "end of line", e.g. getchar() returns EOF when it encounters en error
  • There are many inconsistencies within the standard library, e.g. strncpy() doesn't always append a '\0' and fgets() receives an int parameter to indicate a size (whereas size_t should be used)
  • The standard library is very limited, you often have to use external libraries or write your own library for common things like linked lists


And there are many other examples. C is OK for experienced programmers who have a real reason to use it, but it's too disturbing for beginners.
In my opinion it even easier to learn assembly as a beginner because when you don't understand something, you can be pretty sure that your program will crash.
In C nearly every programmer writes evil code like that because they don't encounter a direct reaction showing them they are wrong :
Code:
char* s1 = "read-only string";  /* if you use GCC add the command-line switch -Wwrite-strings to notice these */
scanf("%s", s2);
fflush(stdin);    

_________________
(French only) http://dap.developpez.com
Post 13 Nov 2008, 19:45
View user's profile Send private message Visit poster's website Reply with quote
Borsuc



Joined: 29 Dec 2005
Posts: 2466
Location: Bucharest, Romania
Borsuc
dap wrote:
  • The static and extern don't have the same meaning in different contexts
Well they are only used in multi-object projects, if you have only one file, it's better to name everything static since it'll allow file optimizations.

And then, if you want multiple files, you can just "include" the .c file (not header) directly just as if you would place it's contents there (like in fasm). Remember not to compile it however. This way you'll have one object file, but many source files. Kinda similar to asm.

(Yes it takes longer to recompile everything but it's no problem for small projects, and since we're talking beginner-level that is implicit).

dap wrote:
  • EOF doesn't mean "end of line", e.g. getchar() returns EOF when it encounters en error
  • You meant "end of file" right?

    BTW: the standard library is NOT C. I don't even use it. The language itself is easy Smile

    dap wrote:
  • There are many inconsistencies within the standard library, e.g. strncpy() doesn't always append a '\0' and fgets() receives an int parameter to indicate a size (whereas size_t should be used)
  • See above.

    dap wrote:
  • The standard library is very limited, you often have to use external libraries or write your own library for common things like linked lists
  • See above.

    in fact, most asm languages come with none, so C should be easy, as a LANGUAGE, if you are used to asm. No need for standard libraries. Wink


    why i like C most is because it is a HLL that is similar to asm in many ways, compared to other HLLs out there which are too abstract.

    _________________
    Previously known as The_Grey_Beast
    Post 13 Nov 2008, 20:30
    View user's profile Send private message Reply with quote
    bitRAKE



    Joined: 21 Jul 2003
    Posts: 2915
    Location: [RSP+8*5]
    bitRAKE
    Here is the MINIPAD example from FASM in C:
    (Hehe...I've never converted anything in that direction before (x86->C), lol.)
    Code:
    #include <tchar.h>
    #include <windows.h> 
    #include "resource.h"
    
    WNDCLASSEX wcx;
    LOGFONT lplf = {16,0,0,0,0,FALSE,FALSE,FALSE,ANSI_CHARSET,OUT_RASTER_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,FIXED_PITCH|FF_DONTCARE,_T( "" )};
    HWND hWndEdit;
    HFONT hFontEdit;
    
    LRESULT CALLBACK WndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam ) {
      RECT client;
      switch( msg ) {
    
        case WM_SIZE:
          GetClientRect( hWnd, &client );
          MoveWindow( hWndEdit, client.left, client.top, client.right, client.bottom, TRUE );
          return 0;
    
        case WM_SETFOCUS:
          SetFocus( hWndEdit );
          return 0;
    
        case WM_COMMAND:
          switch( wParam & 0xFFFF ) {
            case IDM_FILE_NEW:
              SendMessage( hWndEdit, WM_SETTEXT, 0, 0 );
              return 0;
            case IDM_HELP_ABOUT:
              MessageBox( hWnd, _T("Some text..."), _T("About:"), MB_OK );
              return 0;
            case IDM_FILE_EXIT:
              SendMessage( hWnd, WM_CLOSE, 0, 0 );
              return 0;
          }
          break;
    
        case WM_CREATE:
          GetClientRect( hWnd, &client );
          hWndEdit = CreateWindowEx( WS_EX_CLIENTEDGE, _T( "EDIT" ), NULL, WS_VISIBLE | WS_CHILD | WS_HSCROLL | WS_VSCROLL | ES_AUTOHSCROLL | ES_AUTOVSCROLL | ES_MULTILINE, client.left, client.top, client.right, client.bottom, hWnd, NULL, wcx.hInstance, NULL );
          if ( hWndEdit == NULL ) return -1;
          hFontEdit = CreateFontIndirect( &lplf );
          if ( hFontEdit == NULL ) return -1;
          SendMessage( hWndEdit, WM_SETFONT, (WPARAM) hFontEdit, FALSE );
          return 0;
    
        case WM_DESTROY:
          DeleteObject( hFontEdit );
          PostQuitMessage( 0 );
          return 0;
      }
      return DefWindowProc( hWnd, msg, wParam, lParam );
    }
    
    WNDCLASSEX wcx = { sizeof(wcx), CS_VREDRAW | CS_HREDRAW, &WndProc, 0, 0, 0, 0, 0, 1+COLOR_BTNFACE, MAKEINTRESOURCE(IDR_MENU1), _T( "testGUI" ), 0 };
    
    int WinMainCRTStartup() {
      MSG msg;
      int result = -1;
    
      wcx.hInstance = GetModuleHandle( NULL );
      wcx.hIcon = LoadImage( wcx.hInstance, MAKEINTRESOURCE(IDI_APP), IMAGE_ICON, 32, 32, LR_CREATEDIBSECTION );
      wcx.hIconSm = LoadImage( wcx.hInstance, MAKEINTRESOURCE(IDI_APP), IMAGE_ICON, 16, 16, LR_CREATEDIBSECTION );
    
      if ( RegisterClassEx( &wcx ) != 0 ) {
        if ( NULL != CreateWindowEx( 0, _T( "testGUI" ), _T( "Window Title" ), WS_VISIBLE | WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, wcx.hInstance, NULL )) {
          while(0 < (result = GetMessage( &msg, NULL, 0, 0))) {
            TranslateMessage( &msg );
            DispatchMessage( &msg );
          }
        }
      }
      ExitProcess(result); 
    }    
    Post 13 Nov 2008, 21:28
    View user's profile Send private message Visit poster's website Reply with quote
    windwakr



    Joined: 30 Jun 2004
    Posts: 827
    Location: Michigan, USA
    windwakr
    I prefer the look of the assembly version, its more readable to me...lol.
    Post 13 Nov 2008, 21:31
    View user's profile Send private message Reply with quote
    Display posts from previous:
    Post new topic Reply to topic

    Jump to:  
    Goto page Previous  1, 2, 3  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 can attach files in this forum
    You can download files in this forum


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

    Website powered by rwasa.