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

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

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

Post by badidea »

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: 44
Joined: May 20, 2016 8:42

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

Post by Haubitze »

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: 2586
Joined: May 24, 2007 22:10
Location: The Netherlands

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

Post by badidea »

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: 44
Joined: May 20, 2016 8:42

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

Post by Haubitze »

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

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

Post by dodicat »

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: 3373
Joined: Sep 25, 2005 21:54

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

Post by srvaldez »

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
Moderator
Posts: 12081
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

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

Post by fxm »

dodicat wrote:I used exec instead of run.
'Run' (instead of 'Exec') avoids pressing a key twice to exit the program.
fxm
Moderator
Posts: 12081
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

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

Post by fxm »

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: 7976
Joined: Jan 10, 2006 20:30
Location: Scotland

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

Post by dodicat »

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: 2586
Joined: May 24, 2007 22:10
Location: The Netherlands

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

Post by badidea »

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?

Post by sancho3 »

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
Moderator
Posts: 12081
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

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

Post by fxm »

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: 1286
Joined: Oct 19, 2017 15:00
Location: Netherlands
Contact:

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

Post by Munair »

sancho3 wrote:Bear in mind that you could write an entire FreeBASIC program on one line using the colon.
LOL.
paul doe
Moderator
Posts: 1730
Joined: Jul 25, 2017 17:22
Location: Argentina

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

Post by paul doe »

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
Moderator
Posts: 12081
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

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

Post by fxm »

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"]
Post Reply