__FB_MAINFILE__

General discussion for topics related to the FreeBASIC project or its community.
Post Reply
Xusinboy Bekchanov
Posts: 782
Joined: Jul 26, 2018 18:28

__FB_MAINFILE__

Post by Xusinboy Bekchanov »

Now there is __FB_MAIN__ only for modules. Is it possible to add __FB_MAINFILE__?
coderJeff
Site Admin
Posts: 4313
Joined: Nov 04, 2005 14:23
Location: Ontario, Canada
Contact:

Re: __FB_MAINFILE__

Post by coderJeff »

__FB_MAIN__ is only defined in the main module. So ... same for __FB_MAINFILE__?

Does this do what you want?

Code: Select all

#ifdef __FB_MAIN__
#define __FB_MAINFILE__ __FILE__
#endif

#print __FB_MAINFILE__
Xusinboy Bekchanov
Posts: 782
Joined: Jul 26, 2018 18:28

Re: __FB_MAINFILE__

Post by Xusinboy Bekchanov »

coderJeff wrote: Oct 15, 2022 16:35 __FB_MAIN__ is only defined in the main module. So ... same for __FB_MAINFILE__?

Does this do what you want?

Code: Select all

#ifdef __FB_MAIN__
#define __FB_MAINFILE__ __FILE__
#endif

#print __FB_MAINFILE__
No, it doesn't work correctly. I also had this option.
This check is always correct: #if __FB_MAINFILE__ = __FILE__ (error)

But I had to change to this:

Code: Select all

'#Region "Form"
	#if defined(__FB_MAIN__) AndAlso Not defined(__MAIN_FILE__)
		#define __MAIN_FILE__
		Const _MAIN_FILE_ = __FILE__
		#ifdef __FB_WIN32__
			#cmdline "Form1.rc"
		#endif
	#endif
	#include once "mff/Form.bi"
	
	Using My.Sys.Forms
	
	Type Form1Type Extends Form
		
	End Type
	
	Dim Shared Form1 As Form1Type
	
	#if _MAIN_FILE_ = __FILE__
		Form1.MainForm = True
		Form1.Show
		App.Run
	#endif
'#End Region
If it would be possible to __FB_MAINFILE__ with or without a path value then that would be great.

Now it is also possible to do this as indicated in my example, but I thought if there is __FB_MAIN__ why not __FB_MAINFILE__.
Xusinboy Bekchanov
Posts: 782
Joined: Jul 26, 2018 18:28

Re: __FB_MAINFILE__

Post by Xusinboy Bekchanov »

If the user does this, the main file is also incorrectly defined:

Code: Select all

#include once "Form2.frm"
'#Region "Form"
	#if defined(__FB_MAIN__) AndAlso Not defined(__MAIN_FILE__)
		#define __MAIN_FILE__
		Const _MAIN_FILE_ = __FILE__
		#ifdef __FB_WIN32__
			#cmdline "Form1.rc"
		#endif
	#endif
	#include once "mff/Form.bi"
	
	Using My.Sys.Forms
	
	Type Form1Type Extends Form
		
	End Type
	
	Dim Shared Form1 As Form1Type
	
	#if _MAIN_FILE_ = __FILE__
		Form1.MainForm = True
		Form1.Show
		App.Run
	#endif
'#End Region
coderJeff
Site Admin
Posts: 4313
Joined: Nov 04, 2005 14:23
Location: Ontario, Canada
Contact:

Re: __FB_MAINFILE__

Post by coderJeff »

Xusinboy Bekchanov wrote: Oct 15, 2022 17:10 If it would be possible to __FB_MAINFILE__ with or without a path value then that would be great.
If this is not what you want, then I don't understand.

Code: Select all

#if defined(__FB_MAIN__)
	Const __FB_MAINFILE__ = __FILE__
#else
	Const __FB_MAINFILE__ = ""
#endif
For fun, with fbc 1.10.0, but it's hard to read:

Code: Select all

const __FB_MAINFILE__ = __FB_IIF__( __FB_ARG_COUNT__( __FB_MAIN__ ) = 0, __FILE__, "" )
Xusinboy Bekchanov
Posts: 782
Joined: Jul 26, 2018 18:28

Re: __FB_MAINFILE__

Post by Xusinboy Bekchanov »

coderJeff wrote: Oct 16, 2022 0:58
Xusinboy Bekchanov wrote: Oct 15, 2022 17:10 If it would be possible to __FB_MAINFILE__ with or without a path value then that would be great.
If this is not what you want, then I don't understand.

Code: Select all

#if defined(__FB_MAIN__)
	Const __FB_MAINFILE__ = __FILE__
#else
	Const __FB_MAINFILE__ = ""
#endif
For fun, with fbc 1.10.0, but it's hard to read:

Code: Select all

const __FB_MAINFILE__ = __FB_IIF__( __FB_ARG_COUNT__( __FB_MAIN__ ) = 0, __FILE__, "" )
I told the compiler itself to determine this. I have my own solutions for this task as shown in my example.

I don't need such an empty __FB_MAINFILE__:

Code: Select all

Const __FB_MAINFILE__ = ""
If the compiler defines __FB_MAINFILE__, the syntax might be something like this:
Without a path value:

Code: Select all

#ifdef __FB_MAINFILE__
    ' This is the main file
#else
   ' This is not the main file.
#endif
In this variant, the compiler defines __FB_MAINFILE__ only in one file, and in other files (includes) this definition will not be. In the code, this can be done in this way: this define is determined after all the includes.
Or like this:
With a path value:

Code: Select all

#if __FB_MAINFILE__ = __FILE__
    ' This is the main file
#else
   ' This is not the main file.
#endif
In this variant, the compiler defines __FB_MAINFILE__ to be the absolute pathname of the first file passed on the compiler command line.
Post Reply