VAL - 27 kb ?

General FreeBASIC programming questions.
Post Reply
VANYA
Posts: 1889
Joined: Oct 24, 2010 15:16
Location: Ярославль
Contact:

VAL - 27 kb ?

Post by VANYA »

I'm here if you compile this line:
Var hh=Val("55")
then we get the size of program 27 kb. Can I have a buggy for something? Is there an alternative to this function may not be the API?
VANYA
Posts: 1889
Joined: Oct 24, 2010 15:16
Location: Ярославль
Contact:

Post by VANYA »

Found in the file: crt\stdlib.bi function: atof
stylin
Posts: 1253
Joined: Nov 06, 2005 5:19

Post by stylin »

Hi, VANYA. This code produces the expected result for me (FreeBASIC Compiler - Version 0.21.1 (08-11-2010) for win32 (target:win32)):

Code: Select all

Var hh=Val("55")
print hh ' prints 55
To see what version you are using, run

Code: Select all

fbc -version
from a console window. Perhaps there is a problem in another part of your program ?
fxm
Moderator
Posts: 12577
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Post by fxm »

stylin wrote:Hi, VANYA. This code produces the expected result for me (FreeBASIC Compiler - Version 0.21.1 (08-11-2010) for win32 (target:win32))
VANYA exclaims just the size of the program (.exe) in compiling this only line.

Without any line, we obtain already 12 kb!
stylin
Posts: 1253
Joined: Nov 06, 2005 5:19

Post by stylin »

Ah, my apologies, I misunderstood the nature of the post.
VANYA
Posts: 1889
Joined: Oct 24, 2010 15:16
Location: Ярославль
Contact:

Post by VANYA »

To see what version you are using, run
I'm using the latest version.
fxm wrote:
stylin wrote:Hi, VANYA. This code produces the expected result for me (FreeBASIC Compiler - Version 0.21.1 (08-11-2010) for win32 (target:win32))
VANYA exclaims just the size of the program (.exe) in compiling this only line.

Without any line, we obtain already 12 kb!
I without any line, we obtain already 7.5 kb!

and so, too 7.5 кб:
#Include "crt/stdlib.bi"

Var hh= atof ("15.44")+atof ("15.66")
Thanks to all.
The function atof for me.
fxm
Moderator
Posts: 12577
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Post by fxm »

VANYA wrote:
fxm wrote:
stylin wrote:Hi, VANYA. This code produces the expected result for me (FreeBASIC Compiler - Version 0.21.1 (08-11-2010) for win32 (target:win32))
VANYA exclaims just the size of the program (.exe) in compiling this only line.

Without any line, we obtain already 12 kb!
I without any line, we obtain already 7.5 kb!
Yes, I compiled with option -exx as usual!
Theunis Jansen
Posts: 248
Joined: Jul 01, 2010 9:35

Size of an EXE

Post by Theunis Jansen »

Since it is the size of the EXE we must remember that there are overheads etc . I think that the compiler loads some minimum functions from the library which depend on other functions/modules to execute the program. Unfortunately FBC is not as termed "an intelligent compiler" as yet so all functions in that module/library even if they are never called become part of the EXE.
I remember when Pascal 5.1 or so was introduced it had an intelligent compiler and the same program on say Pascal 4 which compiled to 15Kb was only 5Kb when the new intelligent compiler was used. The compiler deleted any function etc that was not referenced from where I assume the "Intelligent" comes from.
I hope I haven't missed the point or made some other Booboo this is recalling something from about 20 years ago which since then I have not looked at.
dodicat
Posts: 8269
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Size of an EXE

Post by dodicat »

Theunis Jansen wrote:Since it is the size of the EXE we must remember that there are overheads etc . I think that the compiler loads some minimum functions from the library which depend on other functions/modules to execute the program. Unfortunately FBC is not as termed "an intelligent compiler" as yet so all functions in that module/library even if they are never called become part of the EXE.
I remember when Pascal 5.1 or so was introduced it had an intelligent compiler and the same program on say Pascal 4 which compiled to 15Kb was only 5Kb when the new intelligent compiler was used. The compiler deleted any function etc that was not referenced from where I assume the "Intelligent" comes from.
I hope I haven't missed the point or made some other Booboo this is recalling something from about 20 years ago which since then I have not looked at.
Hi Theunis Jansen.
I used to use Pascal myself and I always thought that it was an elegant language.
Microsoft, as well as Introducing QB, had a Quick Pascal, I have a copy installed, only about 1Mb, but OOP is available and it produces small exe files and is fast.
Windows 98 had a right mouse click quick view option for files, this would show you all the loaded libraries in an exe file.
I havn't seen it since Win 98, but maybe there's a version somewhere for Win NT, which is the underlying OS for Win 2000, Xp, and I think Vista and Win 7.
Maybe a good project would be to have a QP64, like QB64, and bring forth from DOS a Quick Pascal.
marcov
Posts: 3503
Joined: Jun 16, 2005 9:45
Location: Netherlands
Contact:

Post by marcov »

Hmm. Probably because the string can also contain floating point values, a kind of val is used that also supports floating point values, and probably also octal,binary,hex etc.

And "string <-> floating point" are a major part of nearly every (*) language base runtime.

Maybe there is a variant that only handles integers ? (like atoi or so in C, or val,strtoint in Delphi ?).

Btw this is one of the reasons why in Pascal VAL() is a procedure with a by ref parameter, and not a function.

This way, depending on the type passed (integer of float) the compiler can select different overloaded VAL routines.

(*) I mean languages on the level of FB, FPC, GCC here.
Merick
Posts: 1038
Joined: May 28, 2007 1:52

Post by Merick »

FB might not be an "intelligent compiler" able to discard any unused function in the same module as a function that is being used, but if a library is made up of several modules linked together but only functions in one module are called, it will discard the other modules (unless of course the functions being used depend on functions in the other modules)
marcov
Posts: 3503
Joined: Jun 16, 2005 9:45
Location: Netherlands
Contact:

Post by marcov »

Smartlinking on function level should be possible with CGEN since afaik gcc supports it (but requires extra params)
MichaelW
Posts: 3500
Joined: May 16, 2006 22:34
Location: USA

Post by MichaelW »

In an attempt to determine what is increasing the size of the EXE, I tried removing the not-obviously-essential libraries from the linker command line. For a source consisting of the single statement:

Var hh=Val("55")

If I remove supc++ I get no error, but the EXE size remains at 27KB.

If I remove moldname I get no error, but the EXE size remains at 27KB.

If I remove mingwex I get:

undefined reference to `__strtod'

If I remove gcc I get

undefined reference to `__cmshared_create_or_grab'
dodicat
Posts: 8269
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: VAL - 27 kb ?

Post by dodicat »

VANYA wrote:I'm here if you compile this line:
Var hh=Val("55")
then we get the size of program 27 kb. Can I have a buggy for something? Is there an alternative to this function may not be the API?
Hi VANYA
Intresting to note that on fb18.5 the exe file is 8kb.
Here is a bit of the info produced by Quickview on Win 98 for your single line of code :-



KERNEL32.dll

Functions
AddAtomA
DeleteCriticalSection
EnterCriticalSection
ExitProcess
FindAtomA
GetAtomNameA
GetAtomHandleA
GetProcAddress
InitializeCriticalSection
InterlockedExchange
LeaveCriticalSection
SetUnhandledExceptionFilter
Sleep
VirtualProtect
VirtualQuery

msvcrt.dll

Function Name
__getmainargs
__p_environ
__p__fmode
__set_app_type
_assert
_cexit
_controlfp
_errno
_fmode
_fpreset
_iob
_onexit
_setmode
abort
atexit
exit
fprintf
free
localeconv
malloc
memcpy
realloc
signal
strlen
vfprintf
VANYA
Posts: 1889
Joined: Oct 24, 2010 15:16
Location: Ярославль
Contact:

Post by VANYA »

Hello!

I would have probably not noticed if it had not compared the two codes by size:

1500 term = 30 KB (NEW operator - 12 KB)

624 terms = 74 KB ( operator VAL - 27 KB, NEW - 12 KB)
Post Reply