Recent Posts

Pages: [1] 2 3 ... 10
1
Announcements / BCX Documentation Version 8.0.8, March 28, 2024
« Last post by Robert on March 28, 2024, 05:49:44 PM »
BCX Documentation Version 8.0.8, March 28, 2024

Robert Wishlaw
 ... revised and restructured the REPLACE$ function section.

 ... revised and restructured the REPLACE statement section.

 ... revised and restructured the Using Random Access Files section.

 ... revised the example in the RECLEN statement section.

 ... added a revised example of Mike Henning's Pointer Sort Demo, SortDemo3.bas, to the FINDINTYPE function section.

 ... corrected and revised the TEMPFILENAME$ function section.

 ... corrected and revised the BCX Scripting Procedures page.
2
User Contributions / nonCOMApp_Toolkit (a start)
« Last post by mr_unreliable on March 26, 2024, 11:15:04 AM »
Back during my scripting days, we had fun controlling other apps.  If they were COM apps, then the COM interface made manipulating them easy.  For apps without the COM interface, one had to result to various tricks (remember AppActivate and Sendkeys?).  I called those tricks my nonCOMAppToolkit.

This came to mind recently.  I use the 7-zip utility to make backups. However, when I switched my legacy system from win98 to winXP, I ran into a problem.  With 7-zip, if a file is in use by another app, then 7-zip will report it and then stop.  I worked around this in win98 by programming in exceptions to 7-zip for "busy" files.  But in winXP, there were too many exceptions.  Instead of walking away and letting the backup routine run itself, I had to stick around and click the "close" button (frequently) to get through the backups. I longed for a routine which would click the "close" button for me.

FULL DISCLOSURE: This is not a rewrite of the nonCOMAppToolkit for BCX, it is only a start.  There isn't very much to it.  It will find the 7Z window and the close button, then click it.

Take One.  I used two enums, one to find the 7Z window, and another to find the button.  7Z uses the same button for "cancel" when it's running, and "close" if it's finished but still displaying exceptions.  Then I had a "wait loop" which would check periodically for the "close" button, if any.  In the wait loop I used the two enums to find the button and check whether its caption was "close".  Kindly hold your screams of disparagement and disrespect.

I know what you're thinking: I didn't really need any enums.  You don't need an enum to get the 7-zip window -- just use GetActiveWindow.  That may work 99pct of the time.  As for the second enum to get the close btn, you could use GetDlgItem.  You can get the ctrl ID programmatically, or manually using windows SPY.  And my poor mono-core PIII had trouble keeping up with all those enums.

Take Two.  This is based on two assumptions.  That the hWnd of the 7Z app won't change while it's running, and the hWnd of the btn control won't either.  Also that 7Z will use the same btn control for "cancel" while running, and "close" when finished.  Reasonable enough.  I used an enum to get he 7Z hWnd, and the ctrl ID to get the button hWnd.  Instead of the "wait loop" I used the timer, which was running to update the clock in the statusbar.  So in the timer handler, I look for the button caption to change to "close" then send a button click msg. 

So now this code will go into my backup app, and I expect that I will be able to start the app and walk away, confident that it will keep going to conclusion.

cheers, mru.
developed on winXP, with BCX v7.5.0, and pellesC v6.5. Works on win10.

My Usual Disclaimer.  I worked on this until it was good enough for my purposes.  It could obviously use some code polishing and beautification.  I may get around to that later, but probably not.

If you try running this, you may need to review the filespecs.  The test starts with a BFF, to ask where you want the zip file to go.  I will be zipping up a folder in windows which is guaranteed to show busy files.  I also built in the default location for the 7-zip program, but in your case you may have installed it elsewhere.  On my own systems, it was installed in different places.  If you do have 7Z installed, there is probably a path to it in the registry.  I checked on that location too.  If that doesn't work, you will have to re-adjust the code. 

Are you wondering why I am using 7-zip instead of the prescribed microsoft backup utility built into windows?  That is another topic. 

P.S.  AppActivate is awkward in this situation, as 7Z is using the titlebar instead of the statusbar to show progress of the zipping (in addition to the progress bar).
3
Wish List / Re: Nuclear Option
« Last post by Robert on March 23, 2024, 01:33:26 PM »
llvm g++ simply calls clang and clang does not report the pragma inside a function as an error but simply ignores it
you need to use an non-llvm g++ 13.2 or better, but I won't bother you anymore

Bingo!  That was news to me.  The whole point to my choosing Martin Storsjo's package was
to get away from the issues with the Winlib and Equation Solutions packages. 
That said, I have no desire to play musical chairs with various Mingw installations anymore.

Nuwen 19.0 (64 bit only) from
https://nuwen.net/mingw.html

GCC 13.2.0

Code: [Select]
! #pragma GCC push_options
! #pragma GCC optimize("O0")
FOR INTEGER i = 1 TO 10
 ? LPAD$(STR$(i, 1), 3, ASC("0"))
NEXT
! #pragma GCC pop_options

PAUSE
Code: [Select]
Compiling "E:\t\Temp.cpp" with Nuwen g++.exe
E:\t\Temp.cpp: In function 'int main(int, char**)':
E:\t\Temp.cpp:232:12: error: '#pragma GCC optimize' is not allowed inside functions
  232 |    #pragma GCC optimize("O0")
      |            ^~~

Possible partial solution at

https://stackoverflow.com/questions/62529457/pragma-gcc-optimize-in-function
4
Wish List / Re: Nuclear Option
« Last post by MrBcx on March 23, 2024, 01:16:55 PM »
llvm g++ simply calls clang and clang does not report the pragma inside a function as an error but simply ignores it
you need to use an non-llvm g++ 13.2 or better, but I won't bother you anymore

Bingo!  That was news to me.  The whole point to my choosing Martin Storsjo's package was
to get away from the issues with the Winlib and Equation Solutions packages. 
That said, I have no desire to play musical chairs with various Mingw installations anymore.

5
Wish List / Re: Nuclear Option
« Last post by jbk on March 23, 2024, 12:32:29 PM »
MrBcx
the more recent gcc toolchainns have much better warning and error reporting, if you try the example with gcc-13.2 or above you will see the error message
<edit>
are you using llvm-g++?
llvm g++ simply calls clang and clang does not report the pragma inside a function as an error but simply ignores it
you need to use an non-llvm g++ 13.2 or better, but I won't bother you anymore
6
Wish List / Re: Nuclear Option
« Last post by MrBcx on March 23, 2024, 12:19:24 PM »
MrBcx, in my web search I don't know for certain if I came across documentation that states that the optimize pragma can't be used inside a function, but gcc-13.2 gives this error if the pragma is inside the function main of the example that we have been testing LengthOfInteger.cpp:142:9: error: '#pragma GCC optimize' is not allowed inside functions
clang is happy to compile the program if the clang pragma is inside main but it's completely ignored, perhaps other pragmas are allowed inside functions but not optimize
I will search the web for documentation

JB -- I get a different experience than you. 

When I apply the appropriate #pragma statements cited above to clang and clang++ and gcc and g++ command lines, things work as expected.
Not only do I not get the error message that you reported, I also get correct executables using the #pragmas, albeit the timings are slightly
different (not unexpected) when using clang/clang++  and gcc/g++.

I've been using CLANG from the official LLVM-17.0.2 released in October 2023

and using gcc / g++ from Martin Storsjo's

llvm-mingw-20240308-ucrt-x86_64 from March 2024, which might explain some differences.

For now, I'm simply going to follow my nose and see where it takes me.

7
Wish List / Re: Nuclear Option
« Last post by jbk on March 23, 2024, 10:11:15 AM »
MrBcx, in my web search I don't know for certain if I came across documentation that states that the optimize pragma can't be used inside a function, but gcc-13.2 gives this error if the pragma is inside the function main of the example that we have been testing LengthOfInteger.cpp:142:9: error: '#pragma GCC optimize' is not allowed inside functions
clang is happy to compile the program if the clang pragma is inside main but it's completely ignored, perhaps other pragmas are allowed inside functions but not optimize
I will search the web for documentation
8
Wish List / Re: Nuclear Option
« Last post by MrBcx on March 23, 2024, 09:23:35 AM »
unfortunately pragmas can not be used inside a function

JB,

ChatGpt and Google Gemini both dispute your statement.

Can you post your reference?

I will extend BCX's Optimize Directives for Gcc, Clang, and MSVC but I want to do it correctly.

Thanks

9
Wish List / Re: Nuclear Option
« Last post by Robert on March 22, 2024, 07:39:31 PM »
I prefer
Code: [Select]
#pragma GCC push_options
#pragma GCC optimize("O0")
// your code here
#pragma GCC pop_options

Thanks for your posts jbk.

BCX
$OPTIMIZE OFF/ON
currently supports only LCC and Pelles C

Maybe MrBcx can add, to his to do list, an update for other compilers.

Microsoft
https://learn.microsoft.com/en-us/cpp/preprocessor/optimize?view=msvc-170

Using the optimize pragma with the empty string ("") is a special form of the directive:

When you use the off parameter, it turns all the optimizations, g, s, t, and y, off.

When you use the on parameter, it resets the optimizations to the ones that you specified using the /O compiler option.

Code: [Select]
#pragma optimize( "", off )
/* unoptimized code section */
#pragma optimize( "", on )

gcc
https://gcc.gnu.org/onlinedocs/gcc-7.2.0/gcc/Function-Specific-Option-Pragmas.html#Function-Specific-Option-Pragmas

Code: [Select]
#pragma GCC push_options
#pragma GCC optimize("O0")
// your code here
#pragma GCC pop_options

clang
https://clang.llvm.org/docs/LanguageExtensions.html#extensions-for-selectively-disabling-optimization

Code: [Select]
#pragma clang optimize off

#pragma clang optimize on

References
https://stackoverflow.com/questions/31373885/how-to-change-optimization-level-of-one-function
 
10
Wish List / Re: Nuclear Option
« Last post by jbk on March 22, 2024, 06:27:07 PM »
using clang with atomic I get
Code: [Select]
Time for             recursive:       1349
Time for      divide-iterative:       1350
Time for    multiply-iterative:       1114
Time for         if-statements:       1130
Time for reverse-if-statements:       1177
Time for                log-10:       3860
Time for           binary chop:       1256
if instead of atomic I do
only the main function from Robert's code posted below with the addition of a pragma
Code: [Select]
#pragma clang optimize off
int main (int c, char *v[]) {
//  _Atomic int i, j, k, r;
    int i, j, k, r;
    int s = 1;

    /* Test code:
        printf ("%11d %d\n", INT_MIN, count_recur(INT_MIN));
        for (i = -1000000000; i != 0; i /= 10)
            printf ("%11d %d\n", i, count_recur(i));
        printf ("%11d %d\n", 0, count_recur(0));
        for (i = 1; i != 1000000000; i *= 10)
            printf ("%11d %d\n", i, count_recur(i));
        printf ("%11d %d\n", 1000000000, count_recur(1000000000));
        printf ("%11d %d\n", INT_MAX, count_recur(INT_MAX));
    */

    /* Randomize and create random pool of numbers. */

    srand (time (NULL));
    for (j = 0; j < numof (rndnum); j++) {
        rndnum[j] = s * rand();
        s = -s;
    }
    rndnum[0] = INT_MAX;
    rndnum[1] = INT_MIN;

    /* For testing. */
    for (k = 0; k < numof (rndnum); k++) {
        rt[k] = (fn[1].fnptr)(rndnum[k]);
    }

    /* Test each of the functions in turn. */

    clk[0] = clock();
    for (i = 1; i < numof (fn); i++) {
        for (j = 0; j < 10000; j++) {
            for (k = 0; k < numof (rndnum); k++) {
                r = (fn[i].fnptr)(rndnum[k]);
                /* Test code:
                    if (r != rt[k]) {
                        printf ("Mismatch error [%s] %d %d %d %d\n",
                            fn[i].desc, k, rndnum[k], rt[k], r);
                        return 1;
                    }
                */
            }
        }
        clk[i] = clock();
    }

    /* Print out results. */

    for (i = 1; i < numof (fn); i++) {
        printf ("Time for %s: %10d\n", fn[i].desc, (int)(clk[i] - clk[i-1]));
    }

    return 0;
}
my time is
Code: [Select]
Time for             recursive:        658
Time for      divide-iterative:        566
Time for    multiply-iterative:        438
Time for         if-statements:        519
Time for reverse-if-statements:        502
Time for                log-10:       2730
Time for           binary chop:        487
unfortunately pragmas can not be used inside a function

you cal also use __attribute__ ((optnone)) but I prefer the pragma, it's cleaner syntax and you can also turn optimize back on with #pragma clang optimize on
Pages: [1] 2 3 ... 10