Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #11067

Re: Limiting function input only to __int64 but not int...

From Richard Damon <news.x.richarddamon@xoxy.net>
Newsgroups comp.lang.c++
Subject Re: Limiting function input only to __int64 but not int...
Date 2011-10-24 13:49 -0400
Organization A noiseless patient Spider
Message-ID <j848fe$116$1@dont-email.me> (permalink)
References <j824fk$5bf$1@gregory.bnet.hr> <c59f1d33-57bf-47f9-b23a-90cfff62c8c3@f36g2000vbm.googlegroups.com> <j83v8f$g91$1@gregory.bnet.hr> <is6ba7hjetjr8g1iaj947qjkfmuu6a27lc@4ax.com>

Show all headers | View raw


On 10/24/11 1:17 PM, Robert Wessel wrote:
> On Mon, 24 Oct 2011 17:11:48 +0200, "A"<a@a.a>  wrote:
>
>>
>> "Goran"<goran.pusic@gmail.com>  wrote in message
>> news:c59f1d33-57bf-47f9-b23a-90cfff62c8c3@f36g2000vbm.googlegroups.com...
>>> Out of curiosity... Why? int "is an" __int64 any way you look at this.
>>> Why would it matter?
>>
>> because function requires explicitly __int64 because ID's are 64-bit,
>> providing 32-bit int would ruin ID's that go over the 32-bit boundary. This
>> may happen when I do text-to-int conversions using StrToInt and forget to
>> put StrToInt64 instead.
>>
>> In Borlangearcadero C++ Builder 2010 which I use, these functions output int
>> and __int64 so compiler SHOULD be able to check these but unfortunately it
>> doesn't - even if I enable W8102 Implicit conversion of '%s' to '%s' (C++)
>> but it doesn't do what it is supposed to. I tried casting to wrong type but
>> the warning is still not triggered.
>
>
> Why not use the usual trick of imbedding the handle in a structure?
>
> struct MyHandle(__int64 h;};
>
> And use a MyHandle as the parameter or return value?
>
> Alternatively, explicitly declare forms for those functions using int,
> short, etc., and then never define them - that way the link will fail.
> Better yet, if your compiler supports the new standard, use the
> "=delete" form:
>
> void f(__int64);  //supply actual definition
> void f(int)=delete; //can't be called
>
> Of course that's ugly because of the number of definitions you need to
> supply to cover all of the usual conversions.

Actually, once you define one disallowed form, the rest become 
ambiguous. For example, calling with a "short" neither short->int or 
short->__int64 has a preference, so I believe it should give an error. I 
don't think the =delete removes that version from overload resolution, 
but I haven't looked at it in detail yet.

Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Limiting function input only to __int64 but not int... "A" <a@a.a> - 2011-10-24 00:28 +0200
  Re: Limiting function input only to __int64 but not int... Ian Collins <ian-news@hotmail.com> - 2011-10-24 11:49 +1300
    Re: Limiting function input only to __int64 but not int... Juha Nieminen <nospam@thanks.invalid> - 2011-10-24 08:08 +0000
      Re: Limiting function input only to __int64 but not int... yatremblay@bel1lin202.(none) (Yannick Tremblay) - 2011-10-24 14:24 +0000
  Re: Limiting function input only to __int64 but not int... Marc <marc.glisse@gmail.com> - 2011-10-23 22:52 +0000
    Re: Limiting function input only to __int64 but not int... "A" <a@a.a> - 2011-10-24 01:32 +0200
  Re: Limiting function input only to __int64 but not int... Goran <goran.pusic@gmail.com> - 2011-10-23 23:29 -0700
    Re: Limiting function input only to __int64 but not int... "A" <a@a.a> - 2011-10-24 17:11 +0200
      Re: Limiting function input only to __int64 but not int... Robert Wessel <robertwessel2@yahoo.com> - 2011-10-24 12:17 -0500
        Re: Limiting function input only to __int64 but not int... Richard Damon <news.x.richarddamon@xoxy.net> - 2011-10-24 13:49 -0400
        Re: Limiting function input only to __int64 but not int... "A" <a@a.a> - 2011-10-25 00:12 +0200
          Re: Limiting function input only to __int64 but not int... Richard Damon <news.x.richarddamon@xoxy.net> - 2011-10-24 20:20 -0400
          Re: Limiting function input only to __int64 but not int... Christian Gollwitzer <auriocus@gmx.de> - 2011-10-25 07:27 +0200
            Re: Limiting function input only to __int64 but not int... Arne Mertz <arnemertz@googlemail.com> - 2011-10-26 01:02 -0700
  Re: Limiting function input only to __int64 but not int... Marcel Müller <news.5.maazl@spamgourmet.com> - 2011-10-24 09:18 +0200
    Re: Limiting function input only to __int64 but not int... Ian Collins <ian-news@hotmail.com> - 2011-10-24 20:53 +1300
      Re: Limiting function input only to __int64 but not int... Ian Collins <ian-news@hotmail.com> - 2011-10-24 20:58 +1300

csiph-web