Too restrictive compilation control on dynamic arrays in the main code?

General FreeBASIC programming questions.
badidea
Posts: 1583
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: Too restrictive compilation control on dynamic arrays in the main code?

Postby badidea » Dec 02, 2018 11:56

fxm wrote:@badidea,
you are almost there (there are still 2 points to improve):
- we said twice (only),
- automate your call to the program name, whatever it is.

Code: Select all

sub dothis
   static as long locked
   if locked then return
   print "Greetings from " + __function__
   locked=1
end sub

dothis

'============================
if __FB_ARGC__ = 1 then run(command(0), "x")
'============================

sleep
Haubitze
Posts: 37
Joined: May 20, 2016 8:42

Re: Too restrictive compilation control on dynamic arrays in the main code?

Postby Haubitze » Dec 02, 2018 12:16

here my version for 32 and 64 bit, but i think only for windows.

Code: Select all

sub dothis
    static as long locked
     if locked then return
    print "Greetings from " + __function__
    locked=1
end sub

dothis
'============================
'one code line to be greeted again
'============================
dim x as long ptr=cast(long ptr,@dothis):*(x+iif(sizeof(sub)=4,8896,9928))=0:dothis     '32 and 64 bit fbc
sleep
badidea
Posts: 1583
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: Too restrictive compilation control on dynamic arrays in the main code?

Postby badidea » Dec 02, 2018 12:18

I think that it does not count as one line of code.
And indeed, it does not work on linux here.
The address of locked within dothis also depens on compile options, such as -exx
Last edited by badidea on Dec 02, 2018 13:06, edited 2 times in total.
Haubitze
Posts: 37
Joined: May 20, 2016 8:42

Re: Too restrictive compilation control on dynamic arrays in the main code?

Postby Haubitze » Dec 02, 2018 12:19

what, why not? ;D
dodicat
Posts: 5989
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Too restrictive compilation control on dynamic arrays in the main code?

Postby dodicat » Dec 02, 2018 13:24

You have a method badidea, I used exec instead of run.
in fact mine was
if command(1)<> "1" then exec command(0),"1"
Which is OK on Linux and windows.

@ Haubitze, for your hack
my offsets are
(x+7844) for win 10 32 bit -gen gas.
and (x+10904) in 64 bit.

@Mr Swiss
I suppose that is an obvious way, but it is a bit like sending yourself a Christmas card.

Anyway, thanks for trying everybody.
srvaldez
Posts: 2134
Joined: Sep 25, 2005 21:54

Re: Too restrictive compilation control on dynamic arrays in the main code?

Postby srvaldez » Dec 02, 2018 14:20

perhaps I am missing the point, but if the purpose in the last post is to get two greetings, then why not this

Code: Select all

sub dothis
   static as long locked=0
   print "Greetings from " + __function__
   if locked=0 then
      locked=1
      dothis
   end if
end sub

dothis
sleep
fxm
Posts: 9258
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Too restrictive compilation control on dynamic arrays in the main code?

Postby fxm » Dec 02, 2018 14:21

dodicat wrote:I used exec instead of run.

'Run' (instead of 'Exec') avoids pressing a key twice to exit the program.
fxm
Posts: 9258
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Too restrictive compilation control on dynamic arrays in the main code?

Postby fxm » Dec 02, 2018 14:24

srvaldez wrote:perhaps I am missing the point, but if the purpose in the last post is to get two greetings, then why not this

Code: Select all

sub dothis
   static as long locked=0
   print "Greetings from " + __function__
   if locked=0 then
      locked=1
      dothis
   end if
end sub

dothis
sleep

The goal was to insert a line of code only at the authorized place.
dodicat
Posts: 5989
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Too restrictive compilation control on dynamic arrays in the main code?

Postby dodicat » Dec 02, 2018 15:06

If I do run instead of exec I get things like

Code: Select all

Greetings from DOTHIS
Press any key to continue . . . Greetings from DOTHIS
 

fbide, set to retain the console after program end.
badidea
Posts: 1583
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: Too restrictive compilation control on dynamic arrays in the main code?

Postby badidea » Dec 02, 2018 15:51

Description of the two:
Exec: "transfer temporarily, with arguments", "Transfers control over to an external program. When the program exits, execution resumes immediately after the call to Exec."
Run: "one-way transfer", "Transfers control over to an external program. When the program exits, execution will return to the system."

What does "... execution will return to the system" mean? Does run create an additional thread?

Code: Select all

sub dothis
   static as long locked
   if locked then return
   print "Greetings from " + __function__
   locked=1
end sub

dothis

'============================
if __FB_ARGC__ = 1 then exec(command(0), "x")
'============================

print command(0), command(1)
sleep
Gives me:
Greetings from DOTHIS
Greetings from DOTHIS
./test x
./test

Code: Select all

sub dothis
   static as long locked
   if locked then return
   print "Greetings from " + __function__
   locked=1
end sub

dothis

'============================
if __FB_ARGC__ = 1 then run(command(0), "x")
'============================

print command(0), command(1)
sleep
Gives me:
Greetings from DOTHIS
Greetings from DOTHIS
./test x

So everything after run is not executed?
sancho3
Posts: 358
Joined: Sep 30, 2017 3:22

Re: Too restrictive compilation control on dynamic arrays in the main code?

Postby sancho3 » Dec 02, 2018 22:57

Haubitze wrote:what, why not? ;D

Because the colon operator ':' separates command lines. The left side is one line, the right another.
Bear in mind that you could write an entire FreeBASIC program on one line using the colon.
fxm
Posts: 9258
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Too restrictive compilation control on dynamic arrays in the main code?

Postby fxm » Dec 03, 2018 6:43

After this entertaining intermission, I think it's time to come back to the topic of this thread.
(you can use this thread: 'FreeBASIC syntax challenge games', for any other syntax challenge)
Last edited by fxm on Dec 03, 2018 7:07, edited 2 times in total.
Munair
Posts: 836
Joined: Oct 19, 2017 15:00
Location: 't Zand, NL
Contact:

Re: Too restrictive compilation control on dynamic arrays in the main code?

Postby Munair » Dec 03, 2018 6:46

sancho3 wrote:Bear in mind that you could write an entire FreeBASIC program on one line using the colon.

LOL.
paul doe
Posts: 959
Joined: Jul 25, 2017 17:22
Location: Argentina

Re: Too restrictive compilation control on dynamic arrays in the main code?

Postby paul doe » Dec 03, 2018 10:23

fxm wrote:I proposed to write an article around this subject:
...
But as only one person echoed (paul doe, favorably, but probably already knew the subject), I did not write it.
...

Indeed, but that's not the point. The point would be to document the technique and, if at all possible, in a place that's easy to reach (the aforementioned thread in the 'Documentation' forum).

Speaking of which, I'm still working on documenting the implementations for the 23 Object-Oriented Design Patterns documented by the Gang of Four (22 actually; all of them but the iterator pattern, since FreeBasic doesn't provide the mechanisms to implement it -and overloading the for-next operator isn't the same thing).

Also a suggestion: it would be very nice if the Wiki provided a direct link to that thread, preferably right there in the front page, since it's a pretty useful resource (and will only get better with time).
fxm
Posts: 9258
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Too restrictive compilation control on dynamic arrays in the main code?

Postby fxm » Dec 25, 2018 6:47

paul doe wrote:Also a suggestion: it would be very nice if the Wiki provided a direct link to that thread, preferably right there in the front page, since it's a pretty useful resource (and will only get better with time).

FBWiki → fxm [Added links to "Documentation forum" and its "Index Page of Draft Articles"]

Return to “General”

Who is online

Users browsing this forum: No registered users and 2 guests