From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,9ce095aba33fe8d0 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!wn14feed!worldnet.att.net!bgtnsc05-news.ops.worldnet.att.net.POSTED!53ab2750!not-for-mail From: Dave Thompson Newsgroups: comp.lang.ada Subject: Re: Negative float problem Message-ID: References: <10mspnley7gzu$.1swtj67sv0ldr$.dlg@40tude.net> X-Newsreader: Forte Agent 1.93/32.576 English (American) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Date: Mon, 14 Nov 2005 07:26:10 GMT NNTP-Posting-Host: 12.76.17.213 X-Complaints-To: abuse@worldnet.att.net X-Trace: bgtnsc05-news.ops.worldnet.att.net 1131953170 12.76.17.213 (Mon, 14 Nov 2005 07:26:10 GMT) NNTP-Posting-Date: Mon, 14 Nov 2005 07:26:10 GMT Organization: AT&T Worldnet Xref: g2news1.google.com comp.lang.ada:6370 Date: 2005-11-14T07:26:10+00:00 List-Id: On 01 Nov 2005 19:28:34 -0500, Robert A Duff wrote: > Right. That was my point: functions do not overload on their return > type in C++. > That's true. > It's the same reason why you have to put an annoying "L" at the end of a > "long int" literal in C++. That's a kludge, and it wouldn't work at all > in Ada, which has many integer types. Have I got that right? > No and no. First, you don't always need a suffix L (or LL for long long in C99). Literals have specific types in C and C++ (i.e. no Universal_Integer) and a decimal literal unsuffixed has the smallest signed integer type capable of representing it. On a system with 16-bit int, 1000000 is long int. Where you do need it (or alternatively a cast) is: - when passed as argument (actual) to a function declared without a prototype (obsolete and bad style since 89 but still allowed), or as a variable argument e.g.: printf ("%ld", 3L /* not just 3 */); - when used in certain (arithmetic) expressions: 1000 /* always int */ * 1000 /* ditto */ on system with 16-bit int is computed in 16 bits (not promoted) and overflows, can't produce correct result and may go undiagnosed 1000L * 1000 /* promoted to long, computed in long, safe */ You do more often need a suffix U (or cast) for unsigned -- but not always; octal and hexadecimal (but not decimal) unsuffixed literals of certain sizes are automatically unsigned. And signed ones are silently and losslessly converted if they meet unsigned in an expression. You might write suffixes even where not required, for documentation. Just as I might 'use Foo.Bar' and still write Foo.Bar.X or Bar.X instead of just X. Second, this still has nothing to do with overloading on return type. A numeric literal is not a function, not even in Ada. It can be an argument, and matching and conversion of actual arguments to formal parameters of possible overloads in C++ is basically similar to Ada. - David.Thompson1 at worldnet.att.net