www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 23476] New: Second ImportC example in Quick Examples, Section

https://issues.dlang.org/show_bug.cgi?id=23476

          Issue ID: 23476
           Summary: Second ImportC example in Quick Examples, Section
                    41.1, does not compile
           Product: D
           Version: D2
          Hardware: x86_64
                OS: FreeBSD
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: donaldcallen1942 icloud.com

Compiling the example verbatim with either the released version of DMD or the
current release candidate produces the following:

(dmd-2.101.0-rc.1)dca giovanni:/tmp$ dmd demo.d square.c
demo.d(6): Error: function expected before `()`, not `module square` of type
`void`

This is due to the name conflict between the C module and the function it
contains. Fully qualifying the function name in the D code fixes it:

import std.stdio;
import square;
void main()
{
    int i = 7;
    writefln("The square of %s is %s", i, square.square(i));
}

--
Nov 11 2022