Re[2]: [fpc-pascal] How to solve "variable does not seem to be initialized" compiler hint.
Hello Graeme, Friday, November 20, 2009, 9:42:16 AM, you wrote: GG> I created a local dcpFillChar() which uses a out parameter. Inside the GG> implementation of dcpFillChar() I enabled {$HINTS OFF}, and then called GG> FPC's FillChar(). I had not tested it but you can create a general "Initializers.pas" unit, which redefine FillChar and maybe some others like "Move", them add the unit in the last position in your 3rd party unit and compile. If everything is hint free, you can remove the unit and add a hints off. -- Best regards, JoshyFun ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re[2]: [fpc-pascal] How to solve "variable does not seem to be initialized" compiler hint.
Hello Graeme, Thursday, November 19, 2009, 8:52:41 AM, you wrote: GG> And working with a uninitialized data structure is a good thing? I think GG> not. So, like everybody else, I manually initialise my data structures - GG> and because of my efforts to write safer code, the compiler gives me a GG> hint "variable does not seem to be initialized". The exact opposite of GG> what I was trying to do. So that hint is useless, after I really did fix GG> the potential problem in code. The problem is simply FillChar that uses GG> the wrong parameter type - var instead of out. Its for sure that this discussion will end up in a dead point, things should be different ? Maybe yes. Will it be changed ? No to avoid problems. So as the compiler will issue hints about uninitialized data and FillChar is not the right procedure to initialize nothing except maybe a short string (due its name), why not create some procedures to initialize arrays and memory blocks with a more 21th century names ? Something like "InitializeArray" and "InitializeRecord". Would it require compiler magic ? From my point of view FillChar name does not match a initialize data function. FillMemory (in wininc) is more clear but also it does not "initialize" a string. GG> And now Jonas says the problem cannot be fixed simply because of the GG> select few developers working on Windows+COM projects. The the problem GG> must now be accepted by all because of a VERY specific use-case. That GG> doesn't sound very "cross platform" to me?? out parameters seems to have a "difficult to predict" effects on some types, I think interfaces could be affected by out parameters also and anything that it's auto-freed by the compiler. -- Best regards, JoshyFun ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re[2]: [fpc-pascal] How to solve "variable does not seem to be initialized" compiler hint.
Hello FPC-Pascal, Wednesday, November 18, 2009, 11:00:03 PM, you wrote: MvdV> The procedure in question is a typical initialisation. But because it is MvdV> more library oriented, it pops up. MvdV> But I agree with Jonas. The problem is the obsession to eliminate each and MvdV> every warning, not the hint/warning. It is not an obsession, its a need... I really like the hints and warnings but I must "eliminate" them to "mark" the procedure as ok, or new hints will be oversight hidden by a lot of trees in the forrest ;) For sure I also left some hints here and there :) -- Best regards, JoshyFun ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: Re[2]: [fpc-pascal] How to solve "variable does not seem to be initialized" compiler hint.
On Tue, Nov 17, 2009 at 7:19 PM, JoshyFun wrote: > Hello FPC-Pascal, > > Tuesday, November 17, 2009, 8:47:03 PM, you wrote: > > c> Can the Fill... functions be changed to have the first parameter "out" > c> instead of "var" ? Surely they don't use it as an input parameter. > > Write your own "fillchar" like function and inline it, something like: > > procedure MyFillChar(out x; count: SizeInt; Value: char); inline; > begin > {$PUSH} > {$HINTS OFF} > FillChar(x,count,Value); > {$POP} > end; > > -- > Best regards, > JoshyFun Shouldn't this code too raise a warning? -Flávio ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re[2]: [fpc-pascal] How to solve "variable does not seem to be initialized" compiler hint.
Hello FPC-Pascal, Tuesday, November 17, 2009, 8:47:03 PM, you wrote: c> Can the Fill... functions be changed to have the first parameter "out" c> instead of "var" ? Surely they don't use it as an input parameter. Write your own "fillchar" like function and inline it, something like: procedure MyFillChar(out x; count: SizeInt; Value: char); inline; begin {$PUSH} {$HINTS OFF} FillChar(x,count,Value); {$POP} end; -- Best regards, JoshyFun ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re[2]: [fpc-pascal] How to solve "variable does not seem to be initialized" compiler hint.
>> In my humble opinion, there are no problems with the FillChar declaration. >> But the way you wrote your _absolutely correct_ code produced a hint. You >> shold use $HINTS OFF, for amendment to the FillChar declaration seems to be >> done unlikely. > But there is a reason for the hints. It should point you to possible problems > (or optimitations). When switching it off, you also loose all other hints. > That's not a solution, it's a workaround. As far as I know $HINTS is a local directive. So, you can circumscribe only a certain piece of your code. E.g: {$HINTS OFF} FillChar(Temp,SizeOf(Temp),0); {$HINTS ON} You may consider my point to be a bit conservative, but I really do not think there is something to change about the FillChar declaration. -- Best regards, Fantomas ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re[2]: [fpc-pascal] How to solve "variable does not seem to be initialized" compiler hint.
Hello, Graeme! Tuesday, November 17, 2009, 2:20:18 PM, you wrote: > That you. I agree with JoshyFun though. It seems like it is actually a > problem in the FillChar() definition and that should be fixed, instead of > simply ignoring the hint. > I raised this issue in the fpc-devel mailing list. In my humble opinion, there are no problems with the FillChar declaration. But the way you wrote your _absolutely correct_ code produced a hint. You shold use $HINTS OFF, for amendment to the FillChar declaration seems to be done unlikely. -- Best regards, Fantomas ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal