Author Topic: QB64 vs same coded C/C++ program  (Read 4550 times)

0 Members and 1 Guest are viewing this topic.

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
QB64 vs same coded C/C++ program
« on: July 22, 2019, 01:35:04 am »
I still have a little finish work to do, but basically, I finished the QB64 version of the C/C++/Wn API program I put together a few weeks ago, and posted here: https://www.qb64.org/forum/index.php?topic=1417.0

So that code is about double the size of the one I just finished in QB64, yet, when compiled, the C/C++ one is approx. 1.5 MB, while the QB64 one is nearly double that, at 2.5 MB. So why so much bigger? I know Rob worked on limiting libraries that were not needed, so does anyone know why half the source code of my QB64 program would turn out to be twice the exe size of the C/C++ clone?

Here is the QB64 source, for comparison.

Code: QB64: [Select]
  1. 'DIM lb, mx, my, mz, mf, oldmx, oldmy AS INTEGER 'Mouse variables
  2. 'DIM caps AS INTEGER
  3. 'DIM SHARED prompt_column AS INTEGER
  4. 'DIM SHARED startpos AS INTEGER
  5. 'DIM SHARED vertpos AS INTEGER
  6. 'DIM SHARED endpos AS INTEGER
  7. 'DIM SHARED xx AS INTEGER: ' Cursor row.
  8. 'DIM SHARED yy AS INTEGER: ' Cursor column.
  9. 'DIM SHARED yyseparator AS INTEGER
  10. 'DIM ii, j, j2, k, m1, m2 AS INTEGER
  11. 'DIM ins AS INTEGER
  12. 'DIM flag AS INTEGER ' Indicates highlighting in progress.
  13. 'DIM dir AS INTEGER ' direction of the highlighting left (-) or right (+).
  14. 'DIM hmrk, shift, ctrl AS INTEGER ' hmrk is = -1 when void and when in use, indicates the Position in the text array when highlighting begins.
  15. 'DIM entryrow(vmax) AS INTEGER 'Tracks rows where prompts are present.
  16.  
  17. CONST prompt_length = 17 ' Length of longest prompt.
  18. CONST c1f = 0: CONST c1b = 7 ' Color 1. Foreground and background.
  19. CONST c2f = 7: CONST c2b = 1 ' Color 2. Text highlighting
  20. CONST vmax = 4 ' Number of prompts. Must not exceed rows of screen.
  21.  
  22. DIM entry$(vmax) ' AS STRING 'Text entry array.
  23. DIM xntry(MAX_SIZE) AS STRING 'Cut/Copy array.
  24. DIM paste(MAX_SIZE) AS STRING 'Paste array
  25. DIM prompt(vmax) AS STRING 'Prompt array.
  26.  
  27. MAX_SIZE = 36
  28. debug = 0 'Set to zero to turn of, or non-zero to print variables to screen.
  29. prompt_column = 10 'Number of columns to indent prompts.
  30. startpos = prompt_column + prompt_length - 1
  31. vertpos = 5
  32. endpos = startpos + MAX_SIZE
  33. yyseparator = 2 ' # of blank rows - 1 between prompts. Do not set lower than 1.
  34. ins = 7 ' Cursor vertical height.
  35.  
  36. SetConsoleTitle
  37.  
  38. CALL setconsole(c1f, c1b)
  39.  
  40. CALL GetPrompts(startpos, vertpos, vmax, yyseparator, xx, yy, ins, prompt_column, entryrow(), prompt$())
  41.  
  42. CALL HideCursor(ins)
  43.  
  44. WHILE (1)
  45.     CALL GetConsoleInput(startpos, endpos, vertpos, vmax, yyseparator, xx, yy, ins, MAX_SIZE, c1f, c1b, c2f, c2b, prompt_column, entryrow(), prompt$(), entry$())
  46.  
  47. SUB SetConsoleTitle
  48.     title$ = "Pete's Custom Keyboard Input App"
  49.     _TITLE title$
  50.  
  51. SUB setconsole (c1f, c1b)
  52.     PALETTE 7, 63
  53.     COLOR c1f, c1b
  54.     CLS
  55.  
  56. SUB GetPrompts (startpos, vertpos, vmax, yyseparator, xx, yy, ins, prompt_column, entryrow(), prompt$())
  57.     xx = startpos
  58.     yy = vertpos
  59.  
  60.     prompt$(0) = "Name..........: "
  61.     prompt$(1) = "Address.......: "
  62.     prompt$(2) = "City/State/Zip: "
  63.     prompt$(3) = "Phone.........: "
  64.  
  65.     yy = vertpos
  66.  
  67.     FOR ii = 0 TO vmax - 1
  68.         LOCATE yy, prompt_column
  69.         PRINT prompt$(ii);
  70.         entryrow(ii) = yy
  71.         yy = yy + yyseparator
  72.     NEXT
  73.  
  74.     LOCATE vertpos, startpos
  75.     xx = startpos
  76.     yy = vertpos
  77.  
  78. SUB HideCursor (ins)
  79.     LOCATE , , 1, 7, ins
  80.  
  81. SUB copy (startpos, endpos, vertpos, vmax, yyseparator, xx, yy, ins, MAX_SIZE, prompt_column, entryrow(), prompt$(), entry$(), xntry$, hmrk, flag, dir)
  82.     IF xx - startpos + 1 < hmrk THEN
  83.         m2 = hmrk
  84.         m1 = xx - startpos + 1
  85.     ELSE
  86.         m1 = hmrk
  87.         m2 = xx - startpos + 1
  88.     END IF
  89.     xntry$ = MID$(entry$((yy - vertpos) / yyseparator), m1, m2 - m1)
  90.  
  91. SUB replace (startpos, endpos, vertpos, vmax, yyseparator, xx, yy, ins, MAX_SIZE, prompt_column, entryrow(), prompt$(), entry$(), hmrk, flag, dir)
  92.     j = LEN(entry$((yy - vertpos) / yyseparator))
  93.     COLOR c1f, c1b
  94.     IF xx - startpos + 1 < hmrk THEN
  95.         m2 = hmrk
  96.         m1 = xx - startpos
  97.     ELSE
  98.         m1 = hmrk - 1
  99.         m2 = xx - startpos + 1
  100.     END IF
  101.     entry$((yy - vertpos) / yyseparator) = MID$(entry$((yy - vertpos) / yyseparator), 1, m1) + MID$(entry$((yy - vertpos) / yyseparator), m2)
  102.     LOCATE yy, startpos
  103.     PRINT entry$((yy - vertpos) / yyseparator);
  104.     PRINT STRING$(j - LEN(entry$((yy - vertpos) / yyseparator)), 32);
  105.     IF xx - startpos + 1 > hmrk THEN
  106.         xx = hmrk - 1 + startpos
  107.     END IF
  108.     LOCATE yy, xx
  109.     hmrk = 0
  110.     flag = 0
  111.     dir = 0
  112.  
  113. SUB GetConsoleInput (startpos, endpos, vertpos, vmax, yyseparator, xx, yy, ins, MAX_SIZE, c1f, c1b, c2f, c2b, prompt_column, entryrow(), prompt$(), entry$())
  114.     STATIC drag, dir, flag, hmrk, xntry$
  115.  
  116.     DEF SEG = 0
  117.     ii = PEEK(&H417) MOD 16
  118.     SELECT CASE ii
  119.         CASE 1, 2
  120.             shift = -1
  121.         CASE 4
  122.             ctrl = -1
  123.     END SELECT
  124.     DEF SEG
  125.  
  126.     oldyy = yy
  127.  
  128.     IF drag = 0 THEN
  129.  
  130.         IF flag AND shift = 0 AND hmrk = 0 THEN
  131.             flag = 0 ' Disable flag so character value isn't printed after a shift / release event without highlighting.
  132.         END IF
  133.  
  134.         IF hmrk > 0 THEN
  135.             IF shift AND flag THEN
  136.                 flag = 0
  137.             END IF
  138.         END IF
  139.     END IF
  140.  
  141.     CALL mouse(startpos, vmax, xx, yy, vertpos, yyseparator, hmrk, dir, flag, c1f, c1b, c2f, c2b, drag, prompt_column, MAX_SIZE, shift, ch$, entry$(), entryrow())
  142.  
  143.     IF drag = 0 THEN
  144.         IF ch$ = "" THEN ch$ = INKEY$
  145.         IF ch$ <> "" THEN
  146.             IF ctrl THEN
  147.                 SELECT CASE LCASE$(ch$)
  148.                     CASE CHR$(1) ' Select All
  149.                         LOCATE yy, startpos
  150.                         COLOR c2f, c2b
  151.                         PRINT entry$((yy - vertpos) / yyseparator);
  152.                         COLOR c1f, c1b
  153.                         hmrk = 1
  154.                         flag = -1
  155.                         dir = LEN(entry$((yy - vertpos) / yyseparator))
  156.                         xx = startpos + dir
  157.                         LOCATE yy, xx
  158.  
  159.                     CASE CHR$(3) ' Copy
  160.                         IF hmrk THEN
  161.                             CALL copy(startpos, endpos, vertpos, vmax, yyseparator, xx, yy, ins, MAX_SIZE, prompt_column, entryrow(), prompt$(), entry$(), xntry$, hmrk, flag, dir)
  162.                         END IF
  163.  
  164.                     CASE CHR$(24) ' Cut
  165.                         IF hmrk THEN
  166.                             CALL copy(startpos, endpos, vertpos, vmax, yyseparator, xx, yy, ins, MAX_SIZE, prompt_column, entryrow(), prompt$(), entry$(), xntry$, hmrk, flag, dir)
  167.                             CALL replace(startpos, endpos, vertpos, vmax, yyseparator, xx, yy, ins, MAX_SIZE, prompt_column, entryrow(), prompt$(), entry$(), hmrk, flag, dir)
  168.                         END IF
  169.  
  170.                     CASE CHR$(22) ' Paste
  171.                         IF xntry$ <> "" THEN
  172.                             IF hmrk THEN
  173.                                 CALL replace(startpos, endpos, vertpos, vmax, yyseparator, xx, yy, ins, MAX_SIZE, prompt_column, entryrow(), prompt$(), entry$(), hmrk, flag, dir)
  174.                             END IF
  175.                             m1 = xx - startpos
  176.                             m2 = m1 + 1
  177.                             IF LEN(xntry$) + LEN(entry$((yy - vertpos) / yyseparator)) - (m2 - m1) <= MAX_SIZE - 1 THEN
  178.                                 entry$((yy - vertpos) / yyseparator) = MID$(entry$((yy - vertpos) / yyseparator), 1, m1) + xntry$ + MID$(entry$((yy - vertpos) / yyseparator), m2)
  179.                                 LOCATE yy, startpos
  180.                                 COLOR c1f, c1b
  181.                                 PRINT entry$((yy - vertpos) / yyseparator);
  182.                                 xx = xx + LEN(xntry$)
  183.                                 LOCATE yy, xx
  184.                             ELSE
  185.                                 BEEP ' Contents too large to paste.
  186.                             END IF
  187.                         END IF
  188.                 END SELECT
  189.             ELSE
  190.                 SELECT CASE ch$
  191.                     CASE CHR$(8) ' Backspace
  192.                         ch$ = CHR$(0)
  193.                         IF hmrk > 0 THEN
  194.                             CALL replace(startpos, endpos, vertpos, vmax, yyseparator, xx, yy, ins, MAX_SIZE, prompt_column, entryrow(), prompt$(), entry$(), hmrk, flag, dir)
  195.                         ELSE
  196.                             IF xx > startpos THEN
  197.                                 xx = xx - 1
  198.                                 LOCATE yy, xx
  199.                                 PRINT MID$(entry$((yy - vertpos) / yyseparator), xx - startpos + 2); " ";
  200.                                 entry$((yy - vertpos) / yyseparator) = MID$(entry$((yy - vertpos) / yyseparator), 1, xx - startpos) + MID$(entry$((yy - vertpos) / yyseparator), xx - startpos + 2)
  201.                                 LOCATE yy, xx
  202.                             END IF
  203.                         END IF
  204.                     CASE CHR$(0) + "S" ' Delete
  205.                         IF shift THEN
  206.                             IF hmrk THEN
  207.                                 CALL copy(startpos, endpos, vertpos, vmax, yyseparator, xx, yy, ins, MAX_SIZE, prompt_column, entryrow(), prompt$(), entry$(), xntry$, hmrk, flag, dir)
  208.                                 CALL replace(startpos, endpos, vertpos, vmax, yyseparator, xx, yy, ins, MAX_SIZE, prompt_column, entryrow(), prompt$(), entry$(), hmrk, flag, dir)
  209.                             END IF
  210.  
  211.                         ELSE
  212.                             ch$ = CHR$(0)
  213.                             IF hmrk > 0 THEN
  214.                                 CALL replace(startpos, endpos, vertpos, vmax, yyseparator, xx, yy, ins, MAX_SIZE, prompt_column, entryrow(), prompt$(), entry$(), hmrk, flag, dir)
  215.                             ELSE
  216.                                 IF LEN(entry$((yy - vertpos) / yyseparator)) > 0 AND xx - startpos <= LEN(entry$((yy - vertpos) / yyseparator)) THEN
  217.                                     PRINT MID$(entry$((yy - vertpos) / yyseparator), xx - startpos + 2); " ";
  218.                                     entry$((yy - vertpos) / yyseparator) = MID$(entry$((yy - vertpos) / yyseparator), 1, xx - startpos) + MID$(entry$((yy - vertpos) / yyseparator), xx - startpos + 2)
  219.                                     LOCATE yy, xx
  220.                                 END IF
  221.                             END IF
  222.                         END IF
  223.  
  224.                     CASE CHR$(0) + "H" ' Arrow up
  225.                         ch$ = CHR$(0)
  226.                         IF yy > vertpos THEN
  227.                             yy = yy - yyseparator
  228.                             xx = startpos
  229.                             LOCATE yy, xx
  230.                         END IF
  231.  
  232.                     CASE CHR$(0) + "P", CHR$(13) ' Arrow down, Enter
  233.                         ch$ = CHR$(0)
  234.                         IF (yy - vertpos) / yyseparator + 1 < vmax THEN
  235.                             yy = yy + yyseparator
  236.                             xx = startpos
  237.                             LOCATE yy, xx
  238.                         END IF
  239.  
  240.                     CASE CHR$(0) + "K" ' Arrow left
  241.                         ch$ = CHR$(0)
  242.                         IF xx > startpos THEN
  243.                             IF shift THEN
  244.                                 IF dir <= 0 THEN
  245.                                     IF dir = 0 THEN
  246.                                         hmrk = xx - startpos + 1
  247.                                         flag = -1
  248.                                     END IF
  249.                                     xx = xx - 1
  250.                                     LOCATE yy, xx
  251.                                     COLOR c2f, c2b
  252.                                     PRINT MID$(entry$((yy - vertpos) / yyseparator), xx - startpos + 1, 1)
  253.                                     dir = dir - 1
  254.                                     LOCATE yy, xx
  255.                                 ELSE
  256.                                     xx = xx - 1
  257.                                     LOCATE yy, xx
  258.                                     COLOR c1f, c1b
  259.                                     PRINT MID$(entry$((yy - vertpos) / yyseparator), xx - startpos + 1, 1)
  260.                                     dir = dir - 1
  261.                                     IF dir = 0 THEN
  262.                                         hmrk = 0
  263.                                     END IF
  264.                                     LOCATE yy, xx
  265.                                 END IF
  266.  
  267.                             ELSE
  268.                                 xx = xx - 1
  269.                                 LOCATE yy, xx
  270.                             END IF
  271.                         END IF
  272.  
  273.                     CASE CHR$(0) + "M" ' Arrow right
  274.                         ch$ = CHR$(0)
  275.                         IF xx < endpos - 1 AND xx - startpos < LEN(entry$((yy - vertpos) / yyseparator)) THEN
  276.                             IF shift THEN
  277.                                 IF dir >= 0 THEN
  278.                                     IF dir = 0 THEN
  279.                                         hmrk = xx - startpos + 1
  280.                                         flag = -1
  281.                                     END IF
  282.                                     COLOR c2f, c2b
  283.                                     PRINT MID$(entry$((yy - vertpos) / yyseparator), xx - startpos + 1, 1)
  284.                                     xx = xx + 1
  285.                                     LOCATE yy, xx
  286.                                     dir = dir + 1
  287.                                     LOCATE yy, xx
  288.                                 ELSE
  289.                                     COLOR c1f, c1b
  290.                                     PRINT MID$(entry$((yy - vertpos) / yyseparator), xx - startpos + 1, 1)
  291.                                     xx = xx + 1
  292.                                     dir = dir + 1
  293.                                     IF dir = 0 THEN
  294.                                         hmrk = 0
  295.                                         flag = 0
  296.                                     END IF
  297.                                     LOCATE yy, xx
  298.                                 END IF
  299.                             ELSE
  300.                                 xx = xx + 1
  301.                                 LOCATE yy, xx
  302.                             END IF
  303.                         END IF
  304.  
  305.                     CASE CHR$(0) + "G" ' Home
  306.                         ch$ = CHR$(0)
  307.                         IF xx > startpos THEN
  308.                             IF shift THEN
  309.                                 WHILE xx > startpos
  310.                                     IF dir <= 0 THEN
  311.                                         IF dir = 0 THEN
  312.                                             hmrk = xx - startpos + 1
  313.                                             ' flag is already set.
  314.                                         END IF
  315.                                         xx = xx - 1
  316.                                         LOCATE yy, xx
  317.                                         COLOR c2f, c2b
  318.                                         PRINT MID$(entry$((yy - vertpos) / yyseparator), xx - startpos + 1, 1);
  319.                                         dir = dir - 1
  320.                                         LOCATE yy, xx
  321.                                     ELSE
  322.                                         xx = xx - 1
  323.                                         LOCATE yy, xx
  324.                                         COLOR c1f, c1b
  325.                                         PRINT MID$(entry$((yy - vertpos) / yyseparator), xx - startpos + 1, 1);
  326.                                         dir = dir - 1
  327.                                         IF dir = 0 THEN
  328.                                             hmrk = 0
  329.                                             flag = 0
  330.                                         END IF
  331.                                         LOCATE yy, xx
  332.                                     END IF
  333.                                 WEND
  334.                             ELSE
  335.                                 xx = startpos
  336.                                 LOCATE yy, xx
  337.                             END IF
  338.                         END IF
  339.  
  340.                     CASE CHR$(0) + "O" ' End
  341.                         ch$ = CHR$(0)
  342.                         IF xx < endpos - 1 THEN
  343.                             IF shift THEN
  344.                                 WHILE xx - startpos < LEN(entry$((yy - vertpos) / yyseparator))
  345.                                     IF dir >= 0 THEN
  346.                                         IF dir = 0 THEN
  347.                                             hmrk = xx - startpos + 1
  348.                                             flag = -1
  349.                                         END IF
  350.                                         COLOR c2f, c2b
  351.                                         PRINT MID$(entry$((yy - vertpos) / yyseparator), xx - startpos + 1, 1);
  352.                                         xx = xx + 1
  353.                                         LOCATE yy, xx
  354.                                         dir = dir + 1
  355.                                         LOCATE yy, xx
  356.                                     ELSE
  357.                                         COLOR c1f, c1b
  358.                                         PRINT MID$(entry$((yy - vertpos) / yyseparator), xx - startpos + 1, 1);
  359.                                         xx = xx + 1
  360.                                         dir = dir + 1
  361.                                         IF dir = 0 THEN
  362.                                             hmrk = 0
  363.                                         END IF
  364.                                         LOCATE yy, xx
  365.                                     END IF
  366.                                 WEND
  367.                             ELSE
  368.                                 xx = startpos + LEN(entry$((yy - vertpos) / yyseparator))
  369.                                 LOCATE yy, xx
  370.                             END IF
  371.                         END IF
  372.  
  373.                     CASE CHR$(27)
  374.                         ch$ = CHR$(0)
  375.                         SYSTEM
  376.  
  377.                     CASE CHR$(0) + CHR$(82) ' Insert
  378.                         ch$ = CHR$(0)
  379.                         IF ins = 7 THEN ins = 30 ELSE ins = 7
  380.                         HideCursor ins
  381.  
  382.                     CASE CHR$(32) TO CHR$(126)
  383.                         IF hmrk > 0 THEN
  384.                             CALL replace(startpos, endpos, vertpos, vmax, yyseparator, xx, yy, ins, MAX_SIZE, prompt_column, entryrow(), prompt$(), entry$(), hmrk, flag, dir)
  385.                         END IF
  386.                         IF ins = 30 THEN
  387.                             IF xx - startpos < MAX_SIZE - 1 THEN
  388.                                 MID$(entry$((yy - vertpos) / yyseparator), xx - startpos + 1, 1) = ch$
  389.                                 LOCATE yy, xx
  390.                                 PRINT ch$;
  391.                                 xx = xx + 1
  392.                                 LOCATE yy, xx
  393.                             END IF
  394.                         ELSE
  395.                             IF LEN(entry$((yy - vertpos) / yyseparator)) < MAX_SIZE - 1 THEN
  396.                                 PRINT ch$ + MID$(entry$((yy - vertpos) / yyseparator), xx - startpos + 1);
  397.                                 entry$((yy - vertpos) / yyseparator) = MID$(entry$((yy - vertpos) / yyseparator), 1, xx - startpos) + ch$ + MID$(entry$((yy - vertpos) / yyseparator), xx - startpos + 1)
  398.                                 xx = xx + 1
  399.                                 LOCATE yy, xx
  400.                             END IF
  401.                         END IF
  402.                 END SELECT
  403.             END IF
  404.         END IF
  405.  
  406.         IF shift THEN
  407.             IF flag = 0 THEN
  408.                 flag = -1
  409.             END IF
  410.         ELSE
  411.             IF ch$ <> "" THEN
  412.                 IF flag AND shift = 0 AND LCASE$(ch$) <> "x" AND ctrl = 0 AND ch$ <> CHR$(8) AND ch$ <> CHR$(0) + "S" THEN
  413.                     COLOR c1f, c1b
  414.                     LOCATE oldyy, startpos
  415.                     IF ch$ <> CHR$(0) THEN
  416.                         PRINT ch$;
  417.                     END IF
  418.                     PRINT entry$((oldyy - vertpos) / yyseparator);
  419.                     LOCATE yy, xx
  420.                     hmrk = 0
  421.                     flag = 0
  422.                     dir = 0
  423.                 END IF
  424.             END IF
  425.         END IF
  426.         ch$ = ""
  427.     END IF
  428.  
  429. SUB mouse (startpos, vmax, xx, yy, vertpos, yyseparator, hmrk, dir, flag, c1f, c1b, c2f, c2b, drag, prompt_column, MAX_SIZE, shift, ch$, entry$(), entryrow())
  430.     STATIC doubleclick AS INTEGER, lbdn AS INTEGER, z1, oldmx AS INTEGER, oldmy AS INTEGER, mhl AS INTEGER
  431.     DIM mx AS INTEGER, my AS INTEGER, lb AS INTEGER
  432.  
  433.     LOCATE 20, 1
  434.     COLOR c1f, c1b
  435.     PRINT " oldmx"; oldmx; "  oldmy"; oldmy; "  mx"; mx; "  my"; my; "  lb"; lb; "  lbdn"; lbdn; "  dblclk"; doubleclick; "        "
  436.     PRINT " shift"; shift; "  drag"; drag; "  mhl"; mhl; "  hmrk"; hmrk; "  dir"; dir; "       "
  437.     PRINT " mx"; mx - startpos + 1; "  my"; (my - vertpos) / yyseparator; "  xx"; xx - startpos + 1; "  yy"; (yy - vertpos) / yyseparator; "        "
  438.     LOCATE yy, xx
  439.  
  440.  
  441.     mx = _MOUSEX
  442.     my = _MOUSEY
  443.     lb = _MOUSEBUTTON(1)
  444.  
  445.     IF lb AND flag AND drag = 0 THEN ' Allows highlighting caused by mouse click to be removed in parent sub.
  446.         ch$ = CHR$(0)
  447.         shift = 0
  448.         EXIT SUB
  449.     END IF
  450.  
  451.     IF shift AND lb OR mhl THEN
  452.         IF mhl = 0 THEN ' Shift + click highlighting.
  453.             IF my = yy AND mx <> xx AND mx >= startpos AND mx - startpos <= LEN(entry$((yy - vertpos) / yyseparator)) THEN
  454.                 mhl = mx - startpos + 1
  455.             END IF
  456.         ELSE ' Terminal point reached, end highlighting.
  457.             IF mhl = xx - startpos + 1 THEN mhl = 0: drag = 0: EXIT SUB
  458.         END IF
  459.     END IF
  460.  
  461.     IF LEN(entry$((yy - vertpos) / yyseparator)) THEN
  462.         IF lbdn AND xx <> mx OR mhl THEN ' Combined drag and shift + click highlighting.
  463.             IF mx >= startpos AND mx - startpos <= LEN(entry$((yy - vertpos) / yyseparator)) + 1 THEN
  464.                 IF lb OR mhl THEN
  465.                     IF xx > mx THEN
  466.                         drag = -1
  467.                     ELSE
  468.                         drag = 1
  469.                     END IF
  470.                     GOSUB mousedrag
  471.                     EXIT SUB
  472.                 ELSE
  473.                     drag = 0
  474.                 END IF
  475.             END IF
  476.         END IF
  477.     END IF
  478.  
  479.     IF lb THEN
  480.         LOCATE 2, 1: PRINT "left button down    "
  481.         IF my = yy THEN
  482.             IF mx >= startpos AND mx - startpos <= LEN(entry$((yy - vertpos) / yyseparator)) THEN
  483.                 IF drag = 0 AND shift = 0 THEN yy = my ' Prevents changing rows if a drag is in progress.
  484.                 xx = mx
  485.                 LOCATE yy, xx
  486.                 IF lbdn = 0 THEN lbdn = -1: oldmx = mx: oldmy = my
  487.             END IF
  488.         ELSE
  489.             FOR ii = 0 TO vmax - 1
  490.                 IF my = entryrow(ii) THEN
  491.                     EXIT FOR
  492.                 END IF
  493.             NEXT
  494.             IF my = entryrow(ii) AND drag = 0 AND shift = 0 THEN
  495.                 IF mx >= prompt_column AND mx - startpos <= MAX_SIZE THEN
  496.                     IF mx - startpos > 0 AND mx - startpos <= LEN(entry$(ii)) THEN
  497.                         yy = my: xx = mx
  498.                     ELSE
  499.                         yy = my: xx = startpos
  500.                     END IF
  501.                     LOCATE yy, xx
  502.                     IF lbdn = 0 THEN lbdn = -1
  503.                 END IF
  504.             END IF
  505.         END IF
  506.     ELSE
  507.         IF lbdn THEN
  508.             z1 = TIMER
  509.             LOCATE 2, 1: PRINT "left button released"
  510.             doubleclick = doubleclick + 1
  511.             lbdn = 0
  512.             drag = 0
  513.             mhl = 0
  514.         END IF
  515.     END IF
  516.  
  517.     IF doubleclick = 1 THEN
  518.         IF ABS(z1 - TIMER) > .33 THEN doubleclick = 0
  519.     END IF
  520.  
  521.     IF doubleclick = 2 THEN
  522.         ' Any double click events go here...
  523.         doubleclick = 0
  524.     END IF
  525.     LOCATE yy, xx
  526.  
  527.     EXIT SUB
  528.  
  529.     mousedrag:
  530.     SELECT CASE drag
  531.         CASE IS < 0
  532.             IF dir <= 0 THEN ' highlight to left
  533.                 IF dir = 0 THEN
  534.                     hmrk = xx - startpos + 1
  535.                     shift = -2 ' emulated shift key down
  536.                     flag = -1
  537.                 END IF
  538.                 xx = xx - 1
  539.                 LOCATE yy, xx
  540.                 COLOR c2f, c2b
  541.                 PRINT MID$(entry$((yy - vertpos) / yyseparator), xx - startpos + 1, 1)
  542.                 dir = dir - 1
  543.                 LOCATE yy, xx
  544.             ELSE ' unhighlight to left
  545.                 xx = xx - 1
  546.                 dir = dir - 1
  547.                 LOCATE yy, xx
  548.                 COLOR c1f, c1b
  549.                 PRINT MID$(entry$((yy - vertpos) / yyseparator), xx - startpos + 1, 1)
  550.                 IF dir = 0 THEN
  551.                     hmrk = 0
  552.                     flag = 0
  553.                     shift = 0
  554.                 END IF
  555.                 LOCATE yy, xx
  556.             END IF
  557.         CASE IS > 0
  558.             IF dir >= 0 THEN
  559.                 COLOR c2f, c2b
  560.                 PRINT MID$(entry$((yy - vertpos) / yyseparator), xx - startpos + 1, 1)
  561.                 IF dir = 0 THEN
  562.                     hmrk = xx - startpos + 1
  563.                     flag = -1
  564.                     shift = -2 ' emulated shift key down
  565.                 END IF
  566.                 xx = xx + 1
  567.                 dir = dir + 1
  568.                 LOCATE yy, xx
  569.             ELSE
  570.                 COLOR c1f, c1b
  571.                 PRINT MID$(entry$((yy - vertpos) / yyseparator), xx - startpos + 1, 1)
  572.                 xx = xx + 1
  573.                 dir = dir + 1
  574.                 IF dir = 0 THEN
  575.                     hmrk = 0
  576.                     flag = 0
  577.                     shift = 0
  578.                 END IF
  579.                 LOCATE yy, xx
  580.             END IF
  581.     END SELECT
  582.     RETURN
  583.  

Edited to correct bug in paste function.

Pete
« Last Edit: July 22, 2019, 02:45:34 pm by Pete »
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: QB64 vs same coded C/C++ program
« Reply #1 on: July 22, 2019, 03:36:43 am »
Hi Pete. I know very little C ++, but - do you use OpenGL to draw graphics in a C ++ program? Or you use something else for that? And beyond - I'm no longer absolutely sure here, but if QB64 adds libraries for audio and image decompression (next libraries) automatically, even though no commands using this are used, that might explain the difference in size.

But I say again, I just guess, I never really examined it in depth.

And then there's one more thing. QB64 adds C ++ control mechanisms, many control loops that RhoSigma suggested to turn off over $CHECKING: OFF, which probably doesn't contain your code. We discussed this here:
https://www.qb64.org/forum/index.php?topic=1348.msg105790#msg105790
« Last Edit: July 22, 2019, 03:42:40 am by Petr »

Offline Ashish

  • Forum Resident
  • Posts: 630
  • Never Give Up!
    • View Profile
Re: QB64 vs same coded C/C++ program
« Reply #2 on: July 22, 2019, 08:34:41 am »
...
So that code is about double the size of the one I just finished in QB64, yet, when compiled, the C/C++ one is approx. 1.5 MB, while the QB64 one is nearly double that, at 2.5 MB.
...
2.5MB? I compiled your code and the size of the executable is 2.0MB on my machine.
if (Me.success) {Me.improve()} else {Me.tryAgain()}


My Projects - https://github.com/AshishKingdom?tab=repositories
OpenGL tutorials - https://ashishkingdom.github.io/OpenGL-Tutorials

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: QB64 vs same coded C/C++ program
« Reply #3 on: July 22, 2019, 08:43:16 am »
The biggest issue is that QB64 runs in a OpenGL graphical window.  Even screen 0 programs use OpenGL, unless you program them with $CONSOLE:ONLY, and even the smallest OpenGL program is a couple of MB in size.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: QB64 vs same coded C/C++ program
« Reply #4 on: July 22, 2019, 11:34:05 am »
2.5MB? I compiled your code and the size of the executable is 2.0MB on my machine.

Are you using Windows? If not, maybe that's the reason. If so, that's strange, as the code above compiles to 2.494 KB.

@Steve. I think you nailed it again, Emu. The one I wrote in C/C+ uses the Windows console window. Well cool, that also means that the C/C++ code emited is probably pretty well optimized. Thanks for the reply.

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: QB64 vs same coded C/C++ program
« Reply #5 on: July 22, 2019, 12:26:12 pm »
Are you using Windows? If not, maybe that's the reason. If so, that's strange, as the code above compiles to 2.494 KB.

@Steve. I think you nailed it again, Emu. The one I wrote in C/C+ uses the Windows console window. Well cool, that also means that the C/C++ code emited is probably pretty well optimized. Thanks for the reply.

Pete


LOL someone else eyes are going bad too!
  [ You are not allowed to view this attachment ]  


But even common sense says, no regular QB64 program compiles to less than 2MB.
  [ You are not allowed to view this attachment ]  
« Last Edit: July 22, 2019, 12:34:52 pm by bplus »

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: QB64 vs same coded C/C++ program
« Reply #6 on: July 22, 2019, 12:56:19 pm »
LOL, sorry. Typo. I hit the "." key instead of the "," key. Without my glasses, they all look alike. Sorry if that's too racist for anyone. Actually, come to think of it, the capital "A" key looks like a comma without my reading glasses, too.

2,494 KB

Anyway, thanks for compiling it, Mark. You got exactly what I did. I'm still curious why Ashish got less, unless he's not on Windows or he's using an older version of QB64, but till, I can't see why an older version would be that different.

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: QB64 vs same coded C/C++ program
« Reply #7 on: July 22, 2019, 01:33:01 pm »
Oh dang, I thought it was a debate about MB or KB, I see now Ashish gets .5 MB less than us.

How do you do that Ashish? Are you using special settings from jack or rhoSigma?


Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: QB64 vs same coded C/C++ program
« Reply #8 on: July 22, 2019, 03:33:39 pm »
Oh dang, I thought it was a debate about MB or KB, I see now Ashish gets .5 MB less than us.

How do you do that Ashish? Are you using special settings from jack or rhoSigma?

It may be the difference in 64-bit vs 32-bit compilation versions.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: QB64 vs same coded C/C++ program
« Reply #9 on: July 22, 2019, 04:03:35 pm »
V1.3 is 64-bit, right? I downloaded a 64-bit one you recommended many moons ago, which was, at that time, not part of the official 32-bit release. I liked it, so I kept and used it, until I recently replaced it with the newer version 1.3. That's what I compile those one with, and Mark got the exact same size on his Windows system. Yes, maybe Ashish is using an older 32-bit system, but if so, I wonder why a 64-bit one would require another half meg?

If this was the old days I'd just assume he ran out of disk space, and only 2 of the 2.5 MB code got copied!

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: QB64 vs same coded C/C++ program
« Reply #10 on: July 22, 2019, 10:47:37 pm »
V1.3 is 64-bit, right? I downloaded a 64-bit one you recommended many moons ago, which was, at that time, not part of the official 32-bit release. I liked it, so I kept and used it, until I recently replaced it with the newer version 1.3. That's what I compile those one with, and Mark got the exact same size on his Windows system. Yes, maybe Ashish is using an older 32-bit system, but if so, I wonder why a 64-bit one would require another half meg?

If this was the old days I'd just assume he ran out of disk space, and only 2 of the 2.5 MB code got copied!

Pete

V1.3 offers both a 32-bit version and a 64-bit version.  You can download both, if you want, and compile both 32/64 bit programs, and each will be a different size.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: QB64 vs same coded C/C++ program
« Reply #11 on: July 23, 2019, 12:22:11 am »
I just checked. I definitely have the zip file for the 64-bit version 1.3. I think I'll wait to see what Ashish has. My guess is you are correct, and he is running the 32-bit version.

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: QB64 vs same coded C/C++ program
« Reply #12 on: July 23, 2019, 02:43:00 am »
Size 1.619.968 bytes if is compiled under QB ver 0.978,
       1.842.176 bytes if is compiled under QB ver 1.1
       2.333.184 bytes if is compiled under QB ver 1.2
       2.553.344 bytes if is compiled under QB ver 1.3

This all with 64 bit Windows 7.

The program is nice, the only thing I miss there is visibility of the cursor. He shows up there briefly after a mouse click, but then he is no longer visible. I like the possibility of editing already written text.

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: QB64 vs same coded C/C++ program
« Reply #13 on: July 23, 2019, 03:38:35 am »
Hi Petr,

You can REM out or get rid of these print lines, which obscure the cursor and are present just for testing...

    LOCATE 20, 1
    COLOR c1f, c1b
    PRINT " oldmx"; oldmx; "  oldmy"; oldmy; "  mx"; mx; "  my"; my; "  lb"; lb; "  lbdn"; lbdn; "  dblclk"; doubleclick; "        "
    PRINT " shift"; shift; "  drag"; drag; "  mhl"; mhl; "  hmrk"; hmrk; "  dir"; dir; "       "
    PRINT " mx"; mx - startpos + 1; "  my"; (my - vertpos) / yyseparator; "  xx"; xx - startpos + 1; "  yy"; (yy - vertpos) / yyseparator; "        "
    LOCATE yy, xx

--------------------

The code still needs some work. I'm currently trying to make it into a library, but a few of the variables are being stubborn.

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline Ashish

  • Forum Resident
  • Posts: 630
  • Never Give Up!
    • View Profile
Re: QB64 vs same coded C/C++ program
« Reply #14 on: July 23, 2019, 08:41:16 am »
I am using QB64 x32 V1.3 .
if (Me.success) {Me.improve()} else {Me.tryAgain()}


My Projects - https://github.com/AshishKingdom?tab=repositories
OpenGL tutorials - https://ashishkingdom.github.io/OpenGL-Tutorials