Re: methods with "short"-typed arguments.



On Oct 7, 11:00 am, Lew <l...@xxxxxxxxxxxxx> wrote:
On Oct 7, 10:33 am, bugbear <bugbear@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:



Andreas Leitgeb wrote:
Given a method:
void foo (int x, short y) { ... }

How would I call it with an immediate value for the second argument?

foo ( 42, (short)43);

Or did I miss some postfix-char for short literals (like "L" for long)?
(according tohttp://mindprod.com/jgloss/jcheat.htmlthereisn't one)

I think you can "just do it"

http://www.janeg.ca/scjp/lang/literals.html

>> If an int literal is assigned to a short or
>> a byte and it's value is within legal
>> range, the literal is assumed to be a short or a byte.

I think parameter passing is same as assignment.

It pays to check.

<http://java.sun.com/docs/books/jls/third_edition/html/
conversions.html#5.3>

Method invocation conversions specifically do not include the implicit narrowing
of integer constants which is part of assignment conversion.

That all literals are of int type is a misfeature, IMO - the literal 1
should be of type byte, which can be wideningly-converted to any of
short, int, long, float, or double quite safely. Similarly, 128
should be of type short, and 32768 of type int. This'd probably
eliminate the need for an explicit 'L' qualifier: all literals greater
than 2,147,483,647 or less than -2,147,483,648 would logically be of
type 'long' without further effort.

We'd still need F for floats, though.

Alternately, the type suffixes for literals should be more thorough:
suffixes for literals of all numeric primitive types, including char.
The "implicit narrowing for assignment only" special case is confusing
and unnecessary.

-o
.



Relevant Pages

  • Re: Abnormal program termination
    ... foo.c:4: warning: function declaration isn't a prototype ... Your version is legal under C90 rules, but int mainis more explicit ... float ave(), average; ...
    (comp.lang.c)
  • RTF Render with Scale
    ... float fHorzSizeInches = nHorzSize / 25.4f; ... IntPtr hdc = graphics.GetHdc; ... int nHorzSize = SafeNativeMethods.GetDeviceCaps(hdc, ... PHYSICALWIDTH = 110, ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: RAD vs. performance
    ... work with both int and float. ... name (e.g. "+" for both int and float addition). ... Again, it's a compatibility issue. ... contend that assuming interfaces are equivalent and inferring the most ...
    (comp.lang.misc)
  • (part1b) Han from China teaches you C
    ... int flist, mlist, slist; ... float board_size; ... static void draw_tube(float bottom_radius, float top_radius, ... glVertex3f(xmin, ymin, zmax); glVertex3f; ...
    (comp.lang.c)
  • Re: RTF Render with Scale
    ... float fHorzSizeInches = nHorzSize / 25.4f; ... IntPtr hdc = graphics.GetHdc; ... int nHorzSize = SafeNativeMethods.GetDeviceCaps(hdc, ... PHYSICALWIDTH = 110, ...
    (microsoft.public.dotnet.languages.csharp)