[Issue 22699] New: importC: assignment cannot be used as a condition
    d-bugmail at puremagic.com 
    d-bugmail at puremagic.com
       
    Sun Jan 23 06:32:03 UTC 2022
    
    
  
https://issues.dlang.org/show_bug.cgi?id=22699
          Issue ID: 22699
           Summary: importC: assignment cannot be used as a condition
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: dave287091 at gmail.com
C has the error-prone feature of assignment being an expression.
For example:
// assignexpr.c
int x;
int foo(int y){
    if (x = y) // Error: assignment cannot be used as a condition, perhaps `==`
was meant?
        return 3;
    return 0;
}
The CoreFoundation framework on macOS has a header with an inline function that
uses this feature:
static inline __attribute__((always_inline)) 
void CFStringInitInlineBuffer(CFStringRef str, CFStringInlineBuffer *buf,
CFRange range) {
    buf->theString = str;
    buf->rangeToBuffer = range;
    buf->directCStringBuffer = (buf->directUniCharBuffer =
CFStringGetCharactersPtr(str)) ? ((void*)0) : CFStringGetCStringPtr(str,
kCFStringEncodingASCII);
    buf->bufferedRangeStart = buf->bufferedRangeEnd = 0;
}
--
    
    
More information about the Digitalmars-d-bugs
mailing list