Not sure if I should report this as a bug

2 messages Options
Embed this post
Permalink
Chris Saunders-4

Not sure if I should report this as a bug

Reply Threaded More More options
Print post
Permalink
Here is an interface to an external C function:

 mpf_set_str (rop, str: POINTER; base: INTEGER): INTEGER
   -- Set the value of `rop' from the string in `str'.
   -- The string is of the form `M@N' or, if the base is 10 or less,
alternatively `MeN'.
   -- `M' is the mantissa and `N' is the exponent.
   -- The mantissa is always in the specified base.
   -- The exponent is either in the specified base or, if `base' is
negative, in decimal.
   -- The argument `base' may be in the ranges 2 to 36, or -36 to -2.
   -- Negative values are used to specify that the exponent is in decimal.
   -- Unlike the corresponding mpz function, the base will not be determined
from the
   -- leading characters of the string if base is 0.
   -- This is so that numbers like `0.23' are not interpreted as octal.
   -- White space is allowed in the string, and is simply ignored.
   -- This function returns 0 if the entire string up to the '\0' is a valid
number in
   -- base `base'.
   -- Otherwise it returns -1.
  external
   "C inline use %"gmp.h%""
  alias
   "[
    mpf_set_str((mpf_ptr)$rop, (char *)$str, (int)$base)
   ]"
  end

This compiles fine as is, however, if I add a semicolon at the end of
"mpf_set_str((mpf_ptr)$rop, (char *)$str, (int)$base)" the C code that is
generated by EiffelStudio has a syntax error.  It appends ";)" to the line
above.  Should this be reported as a bug?  In the same class I have other
lines of C code all of which  I have ended with a semicolon.  I originally
had a semicolon at the end of this one and just removed it on a guess.  I
cannot see any reason why it should not be there.

Regards
Chris Saunders

Emmanuel Stapf

RE: Not sure if I should report this as a bug

Reply Threaded More More options
Print post
Permalink
> This compiles fine as is, however, if I add a semicolon at the end of
> "mpf_set_str((mpf_ptr)$rop, (char *)$str, (int)$base)" the C code that is
> generated by EiffelStudio has a syntax error.  It appends ";)" to the

Because it is a function, it is required in the C language to have the return
keyword for specifying what is the return value. However originally before the
ECMA standard, we allowed C inline for function as long as it was a single C
expression and disallowed the return statement. For not breaking the existing
code, i.e. not forcing user to adapt their code to add the missing `return'
statement, we will automatically add `return' if not present, add a cast to the
expected Eiffel type and surround the whole inlining by parenthesizes, which is
what is happening in your case.

The best is to add the return and the semicolon.

Regards,
Manu

------------------------------------------------------------------------  
Eiffel Software
805-685-1006
http://www.eiffel.com       
Customer support: http://support.eiffel.com       
User group: http://groups.eiffel.com/join       
------------------------------------------------------------------------