Feature request: instrisic Defines for console / gui mode

For other topics related to the FreeBASIC project or its community.
fxm
Posts: 8361
Joined: Apr 22, 2009 12:46
Location: Paris (suburb), FRANCE

Re: Feature request: instrisic Defines for console / gui mode

Postby fxm » Sep 12, 2018 8:50

Yes, because "-s console" is taken into account by default, only one flag like "__FB_GUI__" would be justified.
coderJeff
Site Admin
Posts: 2695
Joined: Nov 04, 2005 14:23
Location: Ontario, Canada
Contact:

Re: Feature request: instrisic Defines for console / gui mode

Postby coderJeff » Sep 12, 2018 11:46

@marpon, this looks like a reasonable request. Keep in mind, there are some caveats as mentioned by members here.

As fxm points out, because -s console is "default" on all platforms, only one new define is needed.

As St_W points out, __FB_SUBSYSTEM__ = <string> is more flexible. If other subsystems were added and have meaning to fbc in future, changes to compiler & documentation would be minimal.

As marcov points out, the "-s gui" option only really has meaning to windows application launcher, as the subsystem is a link-time option and affects the bits in the EXE header only.

As jj2007 and caseih point out, this is mostly a run-time behaviour. An EXE can be lanuched from short-cut/explorer where a console window is created, or from a shell (CMD.EXE) prompt where console is inherited. Or even in a "-s gui" could create a graphics window, where SLEEP could be used.

And I will point out that the "-s gui" and therefore "__FB_WIN_GUI__" only has meaning when both compiling and linking to an EXE. It has no meaning, and can't be relied upon when outputting DLL's, object files, or static libs.

@marpon, please don't mind the critism, I offer this as general information.

A full copy of a modified fbc source is not that helpful for the developer/maintainer. They won't know what version you are working from, and they need to search for your changes. This one is fairly simple, but still:
1) preferred is a git hub pull request
2) next to that a diff/patch with current fbc master (or close to current)
In either case, should be using git clone to get the most recent fbc sources and modify those sources.

It is true, this is not difficult feature to add (for me anyway). The compiler changes and documentation additions are minimal. One of my goals is to get others involved, so what I would like to see, is if a member would like to take on the developer role for this; this feature addition is relatively simple, and if the interest is there to practice some skills, to see a feature addition from start-to-finish, and learn some new things a long the way, I can help with that. If not, I can add; it's not at the top of my todo list though.
marpon
Posts: 246
Joined: Dec 28, 2012 13:31
Location: Paris - France

Re: Feature request: instrisic Defines for console / gui mode

Postby marpon » Sep 12, 2018 14:05

@coderJeff thanks for the reply

I agree __FB_WIN_GUI__ could be enought, it is even more simple to implement.

and most remarks are also accepting that direction i think.

... I can add; it's not at the top of my todo list though.

please implement when you can, i really don't know how to do it, i do not generally use github, and have no intention (and not expert enougth) to make evolutions on the compiler code.

this one was just because i estimated, i could be quite easy, mostly reproduccing the "exe;dll.." code.

thanks in advance for your time and implication

marpon
MrSwiss
Posts: 2765
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: Feature request: instrisic Defines for console / gui mode

Postby MrSwiss » Sep 12, 2018 15:20

coderJeff wrote:One of my goals is to get others involved, so what I would like to see, is if a member would like to take on the developer role for this; this feature addition is relatively simple, and if the interest is there to practice some skills, to see a feature addition from start-to-finish, and learn some new things a long the way, I can help with that.

Okay, accepted, I'll try to tackle this one ...
Don't expect any miracles. This is as far as I am, currently:
    1) opened accout on GitHub (Mr-Swiss), I've got one on SF.net, for some time.
    2) cloned (not certain) FreeBASIC/fbc --> https://github.com/Mr-Swiss/FreeBASIC
    3) got confirmation mail (on above)
    4) "Am I on the right track, so far?"
    5) "How to proceed, from here?" (provided, above is a: Yes)
jj2007
Posts: 855
Joined: Oct 23, 2016 15:28
Location: Roma, Italia
Contact:

Re: Feature request: instrisic Defines for console / gui mode

Postby jj2007 » Sep 12, 2018 16:10

Btw what stops you from doing this?

Code: Select all

#define _FB_CONSOLE_ 1
... whatever ---
#if _FB_CONSOLE_
    PRINT "press key to continue"
    sleep
#else
    #error "sleep, used on gui mode"
#endif

A #redefine might be handy, instead, in order to avoid such acrobatics:

Code: Select all

#include "Windows.bi"

#define _FB_CONSOLE_ 0
#if _FB_CONSOLE_
   PRINT "it's meant to be a console app"
   sleep
#else
   MessageBox(0, "seems a GUI app", "Hi", MB_OK)
#endif

#define _FB_CONSOLE2_ 1
#if _FB_CONSOLE2_
   PRINT "oh wait: it's a console app"
   sleep
#else
   MessageBox(0, "still a GUI app", "Hi", MB_OK)
#endif
sleep
marpon
Posts: 246
Joined: Dec 28, 2012 13:31
Location: Paris - France

Re: Feature request: instrisic Defines for console / gui mode

Postby marpon » Sep 13, 2018 6:40

@jj2007

sure you can do
#define _FB_CONSOLE_ 1...

but the beauty of intrinsic define is : it is done by the compiler itself...
i don't know ; i probably was not explicit enougth or may be you don't read carefully
St_W
Posts: 1381
Joined: Feb 11, 2009 14:24
Location: Austria
Contact:

Re: Feature request: instrisic Defines for console / gui mode

Postby St_W » Sep 13, 2018 7:16

MrSwiss wrote:4) "Am I on the right track, so far?"

You should actually fork https://github.com/freebasic/fbc and then clone your personal copy to your local development machine.
It should look like e.g. https://github.com/jayrm/fbc - note the " forked from freebasic/fbc" text under the repository title.
So I suggest to simply delete your existing repo and fork the freebasic/fbc one by using the fork button on the top right. You could probably configure the git remotes for your repo on github manually too, but using the fork button is definitely easier and the intended way to do it.

After you have such a repo with the "forked from freebasic/fbc" subtitle clone that on your development machine. Once you're done stage & commit your changes and push them back to your fork. Finally create a pull request (using GitHub UI; that's not a GIT feature) to merge your changes to the freebasic/fbc repo.

btw there's a very easy to understand description on GitHub that explains it in more detail: https://help.github.com/articles/fork-a-repo/
marpon
Posts: 246
Joined: Dec 28, 2012 13:31
Location: Paris - France

Re: Feature request: instrisic Defines for console / gui mode

Postby marpon » Sep 13, 2018 9:51

@coderjeff

finally i've tried to enter on the github process

and implemented the __FB_GUI__ only in my github marpon/fbc fork

made a pull request from my github > Added __FB_GUI__ intrinsic define #98
hope it worked

can be compiled with 32 or 64

tested with

Code: Select all

#if __FB_GUI__
#include "windows.bi"
messagebox(0, "Gui mode", "info",0)
#else
print "Console mode"
print : print "Any key to close"
sleep
#endif
St_W
Posts: 1381
Joined: Feb 11, 2009 14:24
Location: Austria
Contact:

Re: Feature request: instrisic Defines for console / gui mode

Postby St_W » Sep 13, 2018 10:43

looks okay so far, but you should definitely clean that up before it gets merged. For example:
- squash your 10 commits into a single one with a meaningful commit message (as the changes are rather small)
- using variable names that are consistent with the ones already used in fbc (e.g. have a look at the backend option)
- remove unnecessary comments and whitespaces

If you modify your branch in your fork of the repo the pull request is automatically updated.
btw, as I just saw it: you shouldn't create a pull request from master, but create a specific branch for your fix and use that for your pull request. That's bad practice and you may run into problems for additional/subsequent pull requests.
marpon
Posts: 246
Joined: Dec 28, 2012 13:31
Location: Paris - France

Re: Feature request: instrisic Defines for console / gui mode

Postby marpon » Sep 13, 2018 11:08

St_W wrote:ooks okay so far, but you should definitely clean that up before it gets merged. For example:
- squash your 10 commits into a single one with a meaningful commit message (as the changes are rather small)
- using variable names that are consistent with the ones already used in fbc (e.g. have a look at the backend option)
- remove unnecessary comments and whitespaces

If you modify your branch in your fork of the repo the pull request is automatically updated.
btw, as I just saw it: you shouldn't create a pull request from master, but create a specific branch for your fix and use that for your pull request. That's bad practice and you may run into problems for additional/subsequent pull requests.


sorry, if followed wrong process in github, it was my first attempt. Hope it is usable anyway.
i don't understand your pull indications

for my information what variable name did you noticed ( and what is backend option) ?

i'm always happy to learn...
St_W
Posts: 1381
Joined: Feb 11, 2009 14:24
Location: Austria
Contact:

Re: Feature request: instrisic Defines for console / gui mode

Postby St_W » Sep 13, 2018 12:01

I just wanted to give a few suggestions for improvement, no need to feel sorry. And btw, although I'm quite confident that they are actual improvements I don't guarantee anything as coderJeff has the final say :-)

Once you submit a pull request you can still change its contents until it is merged (or closed). To do so you simply change your branch in your fork. For example, you used the master branch, so if you would do additional commits and push them to your fork they will be automatically added to your existing pull request. The same way you can change existing commits and push them to your fork again (you'll need to force push in that case, because you'le be replacing your commits).

With "have a look at the backend option" I meant the implementation of the "-gen <backend>" argument handling, including FB_BACKEND_* constants, enum, etc. For example I wouldn't use an "is" prefix in enums (e.g. change FB_MODEVIEW_ISGUI to simply FB_MODEVIEW_GUI). Beside that I'd rename it to FB_SUBSYSTEM_WINDOWS, but that's debatable :-)
You may also consider changing the "subsystem" member in FBCCTX type (in fbc.bas) to use your enum type instead of a string. The implementation of the "-gen" option may act as an implementation help for that too.
jj2007
Posts: 855
Joined: Oct 23, 2016 15:28
Location: Roma, Italia
Contact:

Re: Feature request: instrisic Defines for console / gui mode

Postby jj2007 » Sep 13, 2018 12:39

marpon wrote:@jj2007

sure you can do
#define _FB_CONSOLE_ 1...

but the beauty of intrinsic define is : it is done by the compiler itself...
The #define is a one-liner, and the explicit declaration makes the code easier to read. I do such things in Masm all the time; what strikes me here is that FB doesn't allow a redefine.
i don't know ; i probably was not explicit enougth or may be you don't read carefully
Why do simple questions so often trigger subtle insults here? Did I ever allude that you are a lousy coder or unable to read?
marpon
Posts: 246
Joined: Dec 28, 2012 13:31
Location: Paris - France

Re: Feature request: instrisic Defines for console / gui mode

Postby marpon » Sep 13, 2018 13:35

@jj2007

i apologize if my formulation did hurt you, my intention was not to "insult" any people.
"subtle" not me, be sure my english knowledge is not allowing for that.

As i understand now : you are thinking about extending define functionalities...

May be, it could be easier to understand if you make your request visible in a separate topic
because i do not think it is related to this one.

Sorry again
MrSwiss
Posts: 2765
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: Feature request: instrisic Defines for console / gui mode

Postby MrSwiss » Sep 13, 2018 13:37

St_W wrote:Beside that I'd rename it to FB_SUBSYSTEM_WINDOWS, but that's debatable :-)
On debatable:
I'd like it as short as possible, without sacrificing clarity: __FB_SUBSYS_WIN__ (just my two Cent's)

Thanks, for the Fork issue clarification (GitHub).
paul doe
Posts: 782
Joined: Jul 25, 2017 17:22
Location: Argentina

Re: Feature request: instrisic Defines for console / gui mode

Postby paul doe » Sep 13, 2018 14:19

jj2007 wrote:Why do simple questions so often trigger subtle insults here?

I fail to see where the insult is (again). However, I do see that you're unable to grasp the difference between an intrinsic define and a #define provided by the application.

Intrinsic defines are a way for the compiler to expose internal state to the application being compiled, so that the app can branch differently depending on that state (to allow compiling to different platforms, say). A #define is something that the application defines; the preprocessor just replaces the definition with the appropriate text wherever the definition is referenced.

So, allowing for redefinition of an intrinsic (what you propose) makes the definition very non-intrinsic, and thus, pointless.

Return to “Community Discussion”

Who is online

Users browsing this forum: No registered users and 2 guests