Recent

Author Topic: Out Parameter - Test program - funny behaviour  (Read 11063 times)

jc99

  • Hero Member
  • *****
  • Posts: 553
    • My private Site
Re: Out Parameter - Test program - funny behaviour
« Reply #15 on: June 21, 2015, 06:23:37 am »
The problem is that a variable passed as const changes value. That is nonsense, not the 101 value. That one is debatable.
No it isn't. And you have to keep that in mind.

But it's no problem if you keep the IPO-scheme.

const in a Procedure/function declaration only mean that it is passed to the function by reference( a pointer) and you get a warning when you try to write to the memory it is pointing to by that variable. It does NOT mean the memory it is poining to is WRITE-PROTECTED somehow. Something else, even another thread could change that part of the memory.
out in a p/f- declaration should only mean, by reference, and has to be written first, not more not less.
About everything else the programmer has to take care of.
e.G:
Code: [Select]
   pa1 := @a;
   pa2 := @a;
   test(pa1^,pa2^);
« Last Edit: June 21, 2015, 07:07:20 am by jc99 »
OS: Win XP x64, Win 7, Win 7 x64, Win 10, Win 10 x64, Suse Linux 13.2
Laz: 1.4 - 1.8.4, 2.0
https://github.com/joecare99/public
'~|    /''
,_|oe \_,are
If you want to do something for the environment: Twitter: #reduceCO2 or
https://www.betterplace.me/klimawandel-stoppen-co-ueber-preis-reduzieren

Leledumbo

  • Hero Member
  • *****
  • Posts: 8757
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Out Parameter - Test program - funny behaviour
« Reply #16 on: June 21, 2015, 11:44:27 am »
const in a Procedure/function declaration only mean that it is passed to the function by reference( a pointer)
Not anymore since 2.6.0.

jc99

  • Hero Member
  • *****
  • Posts: 553
    • My private Site
Re: Out Parameter - Test program - funny behaviour
« Reply #17 on: June 21, 2015, 02:33:35 pm »
Not anymore since 2.6.0.
Right, now you have the new constref-modifier to go strictly by reference. But is the rest still true, or has it also changed ?
OS: Win XP x64, Win 7, Win 7 x64, Win 10, Win 10 x64, Suse Linux 13.2
Laz: 1.4 - 1.8.4, 2.0
https://github.com/joecare99/public
'~|    /''
,_|oe \_,are
If you want to do something for the environment: Twitter: #reduceCO2 or
https://www.betterplace.me/klimawandel-stoppen-co-ueber-preis-reduzieren

Thaddy

  • Hero Member
  • *****
  • Posts: 14382
  • Sensorship about opinions does not belong here.
Re: Out Parameter - Test program - funny behaviour
« Reply #18 on: June 24, 2015, 12:19:22 pm »
It is still true that you are writing bogus code and it is still true that const parameter passing means that that specific parameter should not EVER change value inside of a procedure or function.

I won't spend more time on this. It's user error plain and simple.
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

jc99

  • Hero Member
  • *****
  • Posts: 553
    • My private Site
Re: Out Parameter - Test program - funny behaviour
« Reply #19 on: June 25, 2015, 12:45:57 am »
It is still true that you are writing bogus code and it is still true that const parameter passing means that that specific parameter should not EVER change value inside of a procedure or function.
1. May I remind you that this discussion is about out-modifier ?
2. Is it just your opinion, or have you actual prove this ?
this would mean the value of that parameter is actual copied to a new memory-location. Which is actually done when you pass a simple parameter without any modifier.

I think you really didn't understand the reason for the introduction of the const-modifier in the first place.
... and even the compiler proves you wrong.
It's working just the way i think it should work. Except for object/strings (non simple variables) where it works once but not twice.
BTW. I have no problem this or the other way, it only should be consistent.
or since we now have an constref-modifier it would be good to have outref-modifier.

Doesn't anyone find it annoying when you use a API-function which is declared with var parameter, that you get these unnecessary 'Variable not initialized'-hints ?
When the out-parameter would be working some of the var-declaration in the API/LCL/FCL could be replaced with out/outref-declaration so you get only these hints which are actually helpful.

Wouldn't that be a good thing ?
OS: Win XP x64, Win 7, Win 7 x64, Win 10, Win 10 x64, Suse Linux 13.2
Laz: 1.4 - 1.8.4, 2.0
https://github.com/joecare99/public
'~|    /''
,_|oe \_,are
If you want to do something for the environment: Twitter: #reduceCO2 or
https://www.betterplace.me/klimawandel-stoppen-co-ueber-preis-reduzieren

Thaddy

  • Hero Member
  • *****
  • Posts: 14382
  • Sensorship about opinions does not belong here.
Re: Out Parameter - Test program - funny behaviour
« Reply #20 on: June 25, 2015, 05:20:59 pm »
I presented you the proof on a plate. It is not a side effect, it is user error. Now stop this charade.
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

jc99

  • Hero Member
  • *****
  • Posts: 553
    • My private Site
Re: Out Parameter - Test program - funny behaviour
« Reply #21 on: June 26, 2015, 12:58:13 am »
I presented you the proof on a plate. It is not a side effect, it is user error. Now stop this charade.
Sorry I can't because the proof you gave, proofed ME right. Because the compiler DID gave hints & a warning.
And it outputs the values I'd expect !
So you find it OK when a program compile without any hints, when someone does such an obvious error ?
It' also seems everybody else is OK with functions giving different results, whether they are declared inline or not.
... I wish those a happy debugging-time, I'll use my time for something more useful ...
PS: As I said before. I know how to workaround this. And I will start ignoring the hints, because they are not useful to me.
OS: Win XP x64, Win 7, Win 7 x64, Win 10, Win 10 x64, Suse Linux 13.2
Laz: 1.4 - 1.8.4, 2.0
https://github.com/joecare99/public
'~|    /''
,_|oe \_,are
If you want to do something for the environment: Twitter: #reduceCO2 or
https://www.betterplace.me/klimawandel-stoppen-co-ueber-preis-reduzieren

jc99

  • Hero Member
  • *****
  • Posts: 553
    • My private Site
Re: Out Parameter - Test program - funny behaviour
« Reply #22 on: June 26, 2015, 04:28:36 pm »
It is still true that you are writing bogus code and it is still true that const parameter passing means that that specific parameter should not EVER change value inside of a procedure or function.
About your opinion about the const-modifyer:
READ THE WIKI: http://wiki.freepascal.org/const
Quote from: ? link=http://wiki.freepascal.org/const
The declaration const in a Pascal program is used to inform the compiler that certain identifiers which are being declared are constants, that is, they are initialized with a specific value at compile time as opposed to a variable which is initialized at run time.

In some Pascal compilers, the Const declaration is used to define variables which are initialized at compile time to a certain specific value, and that the variables so defined can change as the program executes. This can be used for initializing arrays at compile time as opposed to setting values when the program is executed.
So please could you stop YOUR charade !
OS: Win XP x64, Win 7, Win 7 x64, Win 10, Win 10 x64, Suse Linux 13.2
Laz: 1.4 - 1.8.4, 2.0
https://github.com/joecare99/public
'~|    /''
,_|oe \_,are
If you want to do something for the environment: Twitter: #reduceCO2 or
https://www.betterplace.me/klimawandel-stoppen-co-ueber-preis-reduzieren

 

TinyPortal © 2005-2018