Re: *str++ is undefined?

From: Andrey Tarasevich (andreytarasevich_at_hotmail.com)
Date: 03/19/05


Date: Sat, 19 Mar 2005 01:01:38 -0800

Michael B Allen wrote:
> On Sat, 19 Mar 2005 01:30:23 -0500, CBFalconer wrote:
>>>
>>> *str++ = tolower(*str);
>>>
>>> that gcc is complaining about:
>>>
>>> warning: operation on `str' may be undefined
>>
>> No. You are using an undefined value, because the ++ may actually take
>> effect either before or after the other use of the same variable.
>
> That's stupid. The right side of the expression must be evaluated before
> an assignment can be made.
> ...

That's true. But the act of actual assignment consists of one and only
one action: storing the [suitable converted] result of the 'tolower'
call in the destination object of type 'char'. But the process of
_locating_ the destination object is not a part of the act of
assignment. The compiler is free to determine the destination object
_before_ the right-hand side is evaluated, and then perform the actual
assignment after the right hand side is evaluated. For example, the
above expression can be evaluated in accordance with the following schedule

  // Determine the destination
  char* dst = str++;

  // Prepare the operand
  char op = *str;

  // Call the function
  char res = tolower(op);

  // Perform the assignment
  *dst = res;

Or it can be evaluated in accordance with a different schedule

  // Prepare the operand
  char op = *str;

  // Call the function
  char res = tolower(op);

  // Determine the destination
  char* dst = str++;

  // Perform the assignment
  *dst = res;

Note, that both schedules are completely legal, i.e. they don't violate
any sequencing requirements imposed by the language specification. In
both cases the actual assignment is performed at the very end (i.e. "the
right side of the expression is evaluated before the assignment" as you
said). But the outcomes are completely different.

(One can easily come up with yet more possible schedules with yet more
possible outcomes).

--
Best regards,
Andrey Tarasevich


Relevant Pages

  • Re: Leveling Question
    ... say what the resource's Maximum Availability setting is but if it's between ... There is no way leveling can SHIFT that task to ... Don't make the mistake of thinking an assignment of "80%" means he works on ... but it seems to schedule them all on the same day. ...
    (microsoft.public.project)
  • Re: So many questions...so little time...on scheduling and leveling
    ... I got my project scheduled but I had to mostly abandon leveling. ... Leveling produced a schedule that ran for years. ... When I reassign a task from resource A to B in the case when the ... assignment unit % ages and extend the duration for me. ...
    (microsoft.public.project)
  • Re: how can I force MSP to respect the dates I want
    ... You don't tell it your schedule, ... OR I can take the resource that I've assigned 100% and assign him overtime equal to 40 man-hours and that too will shorten the task so it completes when the client requires it to. ... YOU have to experiment with the assignment units or add the overtime hours in order to achieve that. ... You make the decisions about resource allocations and it tells you the results those decisions will obtain for you if you go with that plan. ...
    (microsoft.public.project)
  • Re: how can I force MSP to respect the dates I want
    ... we might have a task that could start 15 Feb according to the predecessor linkages and resource availability so that is where Project has placed it. ... BUT some required parts for that task are on backorder and won't arrive from the vendor before the 20th of Feb - so a Start No Earlier Than constraint is applied to the task in order model that driving influence on the schedule. ... increase the resource assignment from 100% to 200% and Project will shorten ...
    (microsoft.public.project)
  • Re: making bytes out of bits
    ... Since the compiler told you the code was broken, ... char a; ... schwartz2.c:17: warning: suggest parentheses around assignment used as ...
    (comp.lang.c)