Thread overview
[Issue 23864] importC fails on assert( pointer != NULL )
Apr 28, 2023
Walter Bright
May 02, 2023
Walter Bright
May 02, 2023
Walter Bright
May 02, 2023
Walter Bright
May 02, 2023
Walter Bright
April 28, 2023
https://issues.dlang.org/show_bug.cgi?id=23864

Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugzilla@digitalmars.com

--- Comment #1 from Walter Bright <bugzilla@digitalmars.com> ---
The error message I get is:

test.c(6): Error: undefined identifier `NULL`, did you mean `null`?

Is that what you got? NULL is not defined in test.i. NULL is supposed to be a macro defined in <stddef.h>.

gcc also complains that NULL is undefined.

--
April 29, 2023
https://issues.dlang.org/show_bug.cgi?id=23864

--- Comment #2 from emteria_wegwerf@web.de ---
I get

$ dmd test.i
test.c(8): Error: expression expected, not `{`
test.c(8): Error: found `if` when expecting `)`
test.c(8): Error: found `;` when expecting `)`
test.c(8): Error: found `else` when expecting `;` following statement
test.c(8): Error: no type for declarator before `)`
test.c(10): Error: no type for declarator before `return`
test.c(11): Error: no type for declarator before `}`


This also happens if I replace NULL with 0 in test.c. After that, gcc compiles the (regenerated) test.i

--
April 30, 2023
https://issues.dlang.org/show_bug.cgi?id=23864

Steven Schveighoffer <schveiguy@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |schveiguy@gmail.com

--- Comment #3 from Steven Schveighoffer <schveiguy@gmail.com> ---
Walter, this is the same issue I got when building stb_image.h (one of them)

The file I used is here: https://github.com/raysan5/raylib/blob/4.0.0/src/external/stb_image.h

The C file I tried to compile is:

```c
#define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h"
```

The errors I get are:

```
/usr/lib/gcc/x86_64-linux-gnu/11/include/xmmintrin.h(1016): Error: expression
expected, not `__attribute__`
/usr/lib/gcc/x86_64-linux-gnu/11/include/xmmintrin.h(1016): Error: found `int`
when expecting `)`
/usr/lib/gcc/x86_64-linux-gnu/11/include/xmmintrin.h(1017): Error: found `{`
when expecting `;` following `return` statement
/usr/lib/gcc/x86_64-linux-gnu/11/include/xmmintrin.h(1017): Error: found `}`
when expecting `;` following statement
/usr/lib/gcc/x86_64-linux-gnu/11/include/xmmintrin.h(1017): Error: found `)`
instead of statement
stb_image.h(1249): Error: expression expected, not `{`
stb_image.h(1249): Error: found `if` when expecting `)`
stb_image.h(1249): Error: found `;` when expecting `)`
stb_image.h(1249): Error: found `else` when expecting `;` following statement
stb_image.h(1249): Error: no type for declarator before `)`
stb_image.h(1251): Error: no type for declarator before `if`
stb_image.h(1253): Error: no type-specifier for declarator
stb_image.h(1254): Error: no type for declarator before `}`
stb_image.h(1258): Error: no type for declarator before `if`
stb_image.h(1260): Error: found `,` when expecting `)`
stb_image.h(1260): Error: `=`, `;` or `,` expected to end declaration instead
of `*`
stb_image.h(1261): Error: no type for declarator before `}`
stb_image.h(1263): Error: no type for declarator before `return`
stb_image.h(1264): Error: no type for declarator before `}`
stb_image.h(1275): Error: expression expected, not `{`
```
The errors in stb_image.h are assert calls. The ones deep in xmmintrin.h are
some sort of vector call, probably an intrinsic. The code is:

```c
extern __inline __m128 __attribute__((__gnu_inline__, __always_inline__,
__artificial__))
_mm_move_ss (__m128 __A, __m128 __B)
{
  return (__m128) __builtin_shuffle ((__v4sf)__A, (__v4sf)__B,
                                     __extension__
                                     (__attribute__((__vector_size__ (16)))
int)
                                     {4,1,2,3});
}
```

--
May 02, 2023
https://issues.dlang.org/show_bug.cgi?id=23864

--- Comment #4 from Walter Bright <bugzilla@digitalmars.com> ---
(In reply to emteria_wegwerf from comment #2)
> I get
> 
> $ dmd test.i
> test.c(8): Error: expression expected, not `{`

This is because of the expression statement. This problem was fixed with:

https://github.com/dlang/dmd/pull/15093

--
May 02, 2023
https://issues.dlang.org/show_bug.cgi?id=23864

--- Comment #5 from Walter Bright <bugzilla@digitalmars.com> ---
(In reply to Steven Schveighoffer from comment #3)
> Walter, this is the same issue I got when building stb_image.h (one of them)

Your's appears to be a completely different problem, which is:

__attribute__((__vector_size__ (16))) int

--
May 02, 2023
https://issues.dlang.org/show_bug.cgi?id=23864

Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://issues.dlang.org/sh
                   |                            |ow_bug.cgi?id=23875

--
May 02, 2023
https://issues.dlang.org/show_bug.cgi?id=23864

Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |ImportC
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED

--- Comment #6 from Walter Bright <bugzilla@digitalmars.com> ---
Therefore, since the original bug for this issue was fixed, I created a new issue from Steven's report.

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

and closed this one as already fixed.

--