On Tue, Mar 22, 2016 at 4:27 AM, Scott Doctor <scott at scottdoctor.com> wrote:
>
> It is uninitialized. you are setting an initial value within an if
> statement. For the compiler, the code has NOT actually executed. so it does
> not use the value of the variable arbitrary_true_false. If it was a #define
> then it would use the value but still give an error because it is not a
> compiler directive #if but a code if.
>
> The logic is that the first instance of assignment is within a conditional.
> That is a particularly nasty kind of bug and should be reported as an error.
> because if later you decide to change arbitrary_true_false to false, then
> s.x would not be initialized before use. the compiler is correct to issue
> the warning. Give s.x a value after/at initialization, but before the if
> statement to give it a desired initial value then recompile, that should fix
> the error.
>
> Compilers only set the code to initialize the variable at declaration, not
> actually use the values during compile. If it was declared as a constant
> using a compiler directive such as #define, then the compiler would use the
> value in the logic and still give an error, but a different one because the
> conditional would always evaluate true (or false depending on what it was
> set to)
>

The usage is never uninitinalized.  You can pass false all you want,
once you make it ot passing it true, the initialized gets set, and the
thing IS initialized.
There is no cause for warning or error in either of these cases.
There is NEVER a time when it will be used and be unassigned.
See - it's too complex for even human minds to reason through how
could a dumb tool have any hope?
>
> On 03/21/2016 21:31, J Decker wrote:
>>
>> On Mon, Mar 21, 2016 at 8:40 PM, Scott Doctor <scott at scottdoctor.com>
>> wrote:
>>>
>>> you are missing
>>>
>>> using System;
>>
>> whatever.  It still fails because it says the variable is
>> uninitilalized.  THe only thing that doesn't is actually running it.
>>
>> That same pattern not matter what the language triggers warning/error
>> checkers
>>>
>>> ------------
>>> Scott Doctor
>>> scott at scottdoctor.com
>>> ------------------
>>>
>>>
>>> On 3/21/2016 5:21 PM, J Decker wrote:
>>>>
>>>> So far I just see analysis tools fail for the same sorts of valid
>>>> code...
>>>>
>>>> this is a bit of C# but the same idea causes the same warnings and
>>>> there's nothign tecniclally wrong with this.
>>>>
>>>>
>>>>
>>>> class test
>>>> {
>>>>      struct large_struct { public int x; }
>>>>      bool arbitrary_true_false = true;
>>>>      void method()
>>>>      {
>>>>         bool initialized = false;
>>>>         large_struct s;
>>>>         if( arbitrary_true_false )
>>>>         {
>>>>            initialized = true;
>>>>            s.x = 1;
>>>>         }
>>>>         if( initialized )
>>>>         {
>>>>            Console.WriteLine( "this fails(during compile) as
>>>> uninitialized: {0}", s.x );
>>>>         }
>>>>      }
>>>> }
>>>>
>>>> On Mon, Mar 21, 2016 at 4:35 PM, James K. Lowden
>>>> <jklowden at schemamania.org> wrote:
>>>>>
>>>>> On Mon, 21 Mar 2016 13:48:06 -0700
>>>>> Scott Perry <numist at apple.com> wrote:
>>>>>
>>>>>> Compilers allow you to choose your standard; --std=c11 means
>>>>>> something very specific (and unchanging)
>>>>>
>>>>> They do.  And that covers what the standard covers.  The standard also
>>>>> has limits.  It includes constructs that are syntactically permitted
>>>>> but whose behavior is left undefined, known by the scarred as "UB" for
>>>>> "undefined behavior". An example from Clang's discussion is
>>>>>
>>>>>           int i = 10 << 31;
>>>>>
>>>>> The standard says << is a shift operator.  It places no limit on the
>>>>> number of bits to be shifted.  If that number is so large that the
>>>>> product cannot be represented by the assigned variable, that is *not*
>>>>> an error.  The standard allows the compiler to do anything or nothing
>>>>> with it.  As you may imagine, the varieties of anything and nothing are
>>>>> many.
>>>>>
>>>>> Compiler writers are well aware that "nothing" is faster done than
>>>>> "something".  Over time, they have gotten more aggressive in simply
>>>>> deleting UB code.  As a consequence, programmers who thought they wrote
>>>>> standards-conforming code get burned when they upgrade/change
>>>>> compilers.  Mysterious and sometimes subtle errors are introduced by
>>>>> the compiler for the user's benefit.
>>>>>
>>>>> Your googlefu will turn up lots of discussion.  One I liked that wasn't
>>>>> on Page 1:
>>>>>
>>>>>
>>>>>
>>>>> http://blog.frama-c.com/index.php?post/2013/10/09/Overflow-float-integer
>>>>>
>>>>> --jkl
>>>>> _______________________________________________
>>>>> sqlite-users mailing list
>>>>> sqlite-users at mailinglists.sqlite.org
>>>>> http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
>>>>
>>>> _______________________________________________
>>>> sqlite-users mailing list
>>>> sqlite-users at mailinglists.sqlite.org
>>>> http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
>>>>
>>>>
>>> _______________________________________________
>>> sqlite-users mailing list
>>> sqlite-users at mailinglists.sqlite.org
>>> http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
>>
>> _______________________________________________
>> sqlite-users mailing list
>> sqlite-users at mailinglists.sqlite.org
>> http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
>>
>>
>
> --
> ---------------------
> Scott Doctor
> scott at scottdoctor.com
>
>
> _______________________________________________
> sqlite-users mailing list
> sqlite-users at mailinglists.sqlite.org
> http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to