Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #62183 > unrolled thread
| Started by | asetofsymbols@gmail.com |
|---|---|
| First post | 2015-05-17 10:07 -0700 |
| Last post | 2015-05-18 00:40 -0700 |
| Articles | 20 on this page of 62 — 14 participants |
Back to article view | Back to comp.lang.c
determines if it is a signed type asetofsymbols@gmail.com - 2015-05-17 10:07 -0700
Re: determines if it is a signed type Richard Heathfield <rjh@cpax.org.uk> - 2015-05-17 18:12 +0100
Re: determines if it is a signed type asetofsymbols@gmail.com - 2015-05-17 10:34 -0700
Re: determines if it is a signed type asetofsymbols@gmail.com - 2015-05-17 11:09 -0700
Re: determines if it is a signed type Kusalananda <kusalananda@example.com> - 2015-05-17 18:22 +0000
Re: determines if it is a signed type asetofsymbols@gmail.com - 2015-05-17 11:31 -0700
Re: determines if it is a signed type Kusalananda <kusalananda@example.com> - 2015-05-17 19:59 +0000
Re: determines if it is a signed type Keith Thompson <kst-u@mib.org> - 2015-05-17 13:12 -0700
Re: determines if it is a signed type Morris Dovey <mrdovey@iedu.com> - 2015-05-17 19:08 -0500
Re: determines if it is a signed type Morris Dovey <mrdovey@iedu.com> - 2015-05-17 19:46 -0500
Re: determines if it is a signed type Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-05-18 01:59 +0100
Re: determines if it is a signed type Morris Dovey <mrdovey@iedu.com> - 2015-05-17 20:10 -0500
Re: determines if it is a signed type Keith Thompson <kst-u@mib.org> - 2015-05-18 00:37 -0700
Re: determines if it is a signed type Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-05-18 21:15 +0100
Re: determines if it is a signed type Keith Thompson <kst-u@mib.org> - 2015-05-18 15:15 -0700
Re: determines if it is a signed type glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2015-05-18 21:51 +0000
Re: determines if it is a signed type James Kuyper <jameskuyper@verizon.net> - 2015-05-18 18:00 -0400
Re: determines if it is a signed type glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2015-05-18 14:37 +0000
Re: determines if it is a signed type jacobnavia <jacob@jacob.remcomp.fr> - 2015-05-18 17:09 +0200
Re: determines if it is a signed type glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2015-05-18 18:14 +0000
Re: determines if it is a signed type Richard Heathfield <rjh@cpax.org.uk> - 2015-05-18 06:34 +0100
Re: determines if it is a signed type Keith Thompson <kst-u@mib.org> - 2015-05-18 00:43 -0700
Re: determines if it is a signed type Richard Heathfield <rjh@cpax.org.uk> - 2015-05-18 13:56 +0100
Re: determines if it is a signed type Keith Thompson <kst-u@mib.org> - 2015-05-18 08:00 -0700
Re: determines if it is a signed type Richard Heathfield <rjh@cpax.org.uk> - 2015-05-18 20:35 +0100
Re: determines if it is a signed type jacobnavia <jacob@jacob.remcomp.fr> - 2015-05-18 23:08 +0200
Re: determines if it is a signed type Richard Heathfield <rjh@cpax.org.uk> - 2015-05-18 22:32 +0100
Re: determines if it is a signed type jacobnavia <jacob@jacob.remcomp.fr> - 2015-05-19 00:44 +0200
Re: determines if it is a signed type Richard Heathfield <rjh@cpax.org.uk> - 2015-05-19 00:05 +0100
Re: determines if it is a signed type jacobnavia <jacob@jacob.remcomp.fr> - 2015-05-19 01:43 +0200
Re: determines if it is a signed type Richard Heathfield <rjh@cpax.org.uk> - 2015-05-19 01:08 +0100
Re: determines if it is a signed type "Bartc" <bartc@freeuk.com> - 2015-05-19 11:33 +0100
Re: determines if it is a signed type Keith Thompson <kst-u@mib.org> - 2015-05-19 08:15 -0700
Re: determines if it is a signed type "Bartc" <bartc@freeuk.com> - 2015-05-19 19:36 +0100
Re: determines if it is a signed type Keith Thompson <kst-u@mib.org> - 2015-05-19 11:55 -0700
Re: determines if it is a signed type jacobnavia <jacob@jacob.remcomp.fr> - 2015-05-19 11:39 +0200
Re: determines if it is a signed type "Bartc" <bartc@freeuk.com> - 2015-05-19 11:44 +0100
Re: determines if it is a signed type jacobnavia <jacob@jacob.remcomp.fr> - 2015-05-19 12:11 +0200
Re: determines if it is a signed type jadill33@gmail.com - 2015-05-19 05:45 -0700
Re: determines if it is a signed type Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-05-19 15:03 +0100
Re: determines if it is a signed type jadill33@gmail.com - 2015-05-19 08:46 -0700
Re: determines if it is a signed type Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-05-19 17:08 +0100
Re: determines if it is a signed type jadill33@gmail.com - 2015-05-19 09:52 -0700
Re: determines if it is a signed type Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-05-19 20:36 +0100
Re: determines if it is a signed type jadill33@gmail.com - 2015-05-20 07:40 -0700
Re: determines if it is a signed type Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-05-20 23:12 +0100
Re: determines if it is a signed type jadill33@gmail.com - 2015-05-21 13:52 -0700
Re: determines if it is a signed type Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-05-21 22:48 +0100
Re: determines if it is a signed type jadill33@gmail.com - 2015-05-22 05:50 -0700
Re: determines if it is a signed type Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-05-22 23:14 +0100
Re: determines if it is a signed type jadill33@gmail.com - 2015-05-26 14:31 -0700
Re: determines if it is a signed type Tim Rentsch <txr@alumni.caltech.edu> - 2015-05-22 23:32 -0700
Re: determines if it is a signed type David Brown <david.brown@hesbynett.no> - 2015-05-20 12:26 +0200
Re: determines if it is a signed type Richard Heathfield <rjh@cpax.org.uk> - 2015-05-19 15:28 +0100
Re: determines if it is a signed type raltbos@xs4all.nl (Richard Bos) - 2015-05-23 10:37 +0000
Re: determines if it is a signed type Keith Thompson <kst-u@mib.org> - 2015-05-18 15:21 -0700
Re: determines if it is a signed type Richard Heathfield <rjh@cpax.org.uk> - 2015-05-19 00:04 +0100
Re: determines if it is a signed type Keith Thompson <kst-u@mib.org> - 2015-05-19 08:03 -0700
Re: determines if it is a signed type David Brown <david.brown@hesbynett.no> - 2015-05-19 08:47 +0200
Re: determines if it is a signed type Keith Thompson <kst-u@mib.org> - 2015-05-19 08:07 -0700
Re: determines if it is a signed type James Kuyper <jameskuyper@verizon.net> - 2015-05-18 11:28 -0400
Re: determines if it is a signed type Keith Thompson <kst-u@mib.org> - 2015-05-18 00:40 -0700
Page 1 of 4 [1] 2 3 4 Next page →
| From | asetofsymbols@gmail.com |
|---|---|
| Date | 2015-05-17 10:07 -0700 |
| Subject | determines if it is a signed type |
| Message-ID | <6a4be947-376c-466e-aa9f-78a6e174725c@googlegroups.com> |
a way for know C type T is signed T a=-1, b; b=a/2; if(b==0||b==-1) signed else. unsigned Is it right? Is there any better way?
[toc] | [next] | [standalone]
| From | Richard Heathfield <rjh@cpax.org.uk> |
|---|---|
| Date | 2015-05-17 18:12 +0100 |
| Message-ID | <mjai3l$aau$1@dont-email.me> |
| In reply to | #62183 |
On 17/05/15 18:07, asetofsymbols@gmail.com wrote: > a way for know > C type T is signed > T a=-1, b; > b=a/2; > if(b==0||b==-1) signed > else. unsigned > Is it right? > Is there any better way? There's a much better way. Look at the definition statement. -- Richard Heathfield Email: rjh at cpax dot org dot uk "Usenet is a strange place" - dmr 29 July 1999 Sig line 4 vacant - apply within
[toc] | [prev] | [next] | [standalone]
| From | asetofsymbols@gmail.com |
|---|---|
| Date | 2015-05-17 10:34 -0700 |
| Message-ID | <fede906b-6acd-4d7d-8c12-06ef955e36fe@googlegroups.com> |
| In reply to | #62185 |
One other way could be T a=1; if(-a<0) signed else. Unsigned
[toc] | [prev] | [next] | [standalone]
| From | asetofsymbols@gmail.com |
|---|---|
| Date | 2015-05-17 11:09 -0700 |
| Message-ID | <65c19651-cc4f-4a30-a560-586087436b7f@googlegroups.com> |
| In reply to | #62189 |
One other way could be T a; a= -1; if(a<0) signed else Unsigned
[toc] | [prev] | [next] | [standalone]
| From | Kusalananda <kusalananda@example.com> |
|---|---|
| Date | 2015-05-17 18:22 +0000 |
| Message-ID | <slrnmlhn2t.2net.kusalananda@macbook-air.local> |
| In reply to | #62189 |
On 2015-05-17, asetofsymbols@gmail.com <asetofsymbols@gmail.com> wrote: > One other way could be > T a=1; > if(-a<0) signed > else. Unsigned Did you actually try this? -- :: Andreas Kusalananda Kahari :: :: Uppsala University, Sweden :: :: a n d r e a s . k a h a r i :: :: @ i c m . u u . s e ::
[toc] | [prev] | [next] | [standalone]
| From | asetofsymbols@gmail.com |
|---|---|
| Date | 2015-05-17 11:31 -0700 |
| Message-ID | <757e37cc-be38-4a83-afb2-1e98bc1b8009@googlegroups.com> |
| In reply to | #62191 |
Kusalananda wrote" On 2015-05-17, asetof...@gmail.com <asetof...@gmail.com> wrote: > One other way could be > T a=1; > if(-a<0) signed > else. Unsigned Did you actually try this? " Not i try: T a; a= -1; if(a<0)goto label; It seems ok in C++, if i define a conversion routine from integer to each T type but would be OT...
[toc] | [prev] | [next] | [standalone]
| From | Kusalananda <kusalananda@example.com> |
|---|---|
| Date | 2015-05-17 19:59 +0000 |
| Message-ID | <slrnmlhs66.2ng1.kusalananda@macbook-air.local> |
| In reply to | #62192 |
On 2015-05-17, asetofsymbols@gmail.com <asetofsymbols@gmail.com> wrote: > Kusalananda wrote" > > On 2015-05-17, asetof...@gmail.com <asetof...@gmail.com> wrote: >> One other way could be >> T a=1; >> if(-a<0) signed >> else. Unsigned > > > Did you actually try this? > " > Not i try: > T a; > a= -1; > if(a<0)goto label; > > It seems ok in C++, if i define > a conversion routine from > integer to each T type > but would be OT... > If you tried it in C, you would quite likely notice a warning produced by the compiler when the unknown type T is unsigned. It knows when the type is signed or unsigned at the time of compilation. Why don't you? -- :: Andreas Kusalananda Kahari :: :: Uppsala University, Sweden :: :: a n d r e a s . k a h a r i :: :: @ i c m . u u . s e ::
[toc] | [prev] | [next] | [standalone]
| From | Keith Thompson <kst-u@mib.org> |
|---|---|
| Date | 2015-05-17 13:12 -0700 |
| Message-ID | <874mnb9d4v.fsf@kst-u.example.com> |
| In reply to | #62183 |
asetofsymbols@gmail.com writes:
> a way for know
> C type T is signed
> T a=-1, b;
> b=a/2;
> if(b==0||b==-1) signed
> else. unsigned
> Is it right?
> Is there any better way?
Given a numeric type T (presumably a typedef name):
if ((T)-1 > 0) {
puts("T is unsigned");
}
else if ((T)1 / 2 == 0) {
puts("T is signed");
}
else {
puts("T is floating-point");
}
--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
Working, but not speaking, for JetHead Development, Inc.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
[toc] | [prev] | [next] | [standalone]
| From | Morris Dovey <mrdovey@iedu.com> |
|---|---|
| Date | 2015-05-17 19:08 -0500 |
| Message-ID | <mjbai5$u51$1@speranza.aioe.org> |
| In reply to | #62183 |
On 5/17/15 12:07 PM, asetofsymbols@gmail.com wrote: > Is there any better way? Of course - look at the declaration! If you’re too lazy to do that, you could try (untested) #define IS_SIGNED(t) (((t) < 0) || (-(t) < 0) || (~(t) < 0)) -- Morris Dovey http://www.iedu.com/Solar
[toc] | [prev] | [next] | [standalone]
| From | Morris Dovey <mrdovey@iedu.com> |
|---|---|
| Date | 2015-05-17 19:46 -0500 |
| Message-ID | <mjbcpp$27m$1@speranza.aioe.org> |
| In reply to | #62207 |
On 5/17/15 7:08 PM, Morris Dovey wrote: > On 5/17/15 12:07 PM, asetofsymbols@gmail.com wrote: >> Is there any better way? > > Of course - look at the declaration! > > If you’re too lazy to do that, you could try > > #define IS_SIGNED(t) (((t) < 0) || (-(t) < 0) || (~(t) < 0)) OTOH... #define IS_SIGNED(t) (((t) < 0) || (-(t) < 0) || (((t) - 1) < 0)) appears to work for floating point as well as integer types :-) -- Morris Dovey http://www.iedu.com/Solar
[toc] | [prev] | [next] | [standalone]
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Date | 2015-05-18 01:59 +0100 |
| Message-ID | <87oalilmz9.fsf@bsb.me.uk> |
| In reply to | #62207 |
Morris Dovey <mrdovey@iedu.com> writes: > On 5/17/15 12:07 PM, asetofsymbols@gmail.com wrote: >> Is there any better way? > > Of course - look at the declaration! > > If you’re too lazy to do that, you could try (untested) > > #define IS_SIGNED(t) (((t) < 0) || (-(t) < 0) || (~(t) < 0)) Hmm... Not, I think, 100% portable in that on a ones' complement machine with "normal" negative zeros, C permits ~t to be zero (i.e. not < 0). -- Ben.
[toc] | [prev] | [next] | [standalone]
| From | Morris Dovey <mrdovey@iedu.com> |
|---|---|
| Date | 2015-05-17 20:10 -0500 |
| Message-ID | <mjbe5c$51m$1@speranza.aioe.org> |
| In reply to | #62209 |
On 5/17/15 7:59 PM, Ben Bacarisse wrote: > Hmm... Not, I think, 100% portable in that on a ones' complement > machine with "normal" negative zeros, C permits ~t to be zero (i.e. > not < 0). Yes. I experienced some vague discomfort with what I'd written and got rid of the '~'. :-) -- Morris Dovey http://www.iedu.com/Solar
[toc] | [prev] | [next] | [standalone]
| From | Keith Thompson <kst-u@mib.org> |
|---|---|
| Date | 2015-05-18 00:37 -0700 |
| Message-ID | <87vbfqqqtz.fsf@kst-u.example.com> |
| In reply to | #62209 |
Ben Bacarisse <ben.usenet@bsb.me.uk> writes:
> Morris Dovey <mrdovey@iedu.com> writes:
>> On 5/17/15 12:07 PM, asetofsymbols@gmail.com wrote:
>>> Is there any better way?
>>
>> Of course - look at the declaration!
>>
>> If you’re too lazy to do that, you could try (untested)
>>
>> #define IS_SIGNED(t) (((t) < 0) || (-(t) < 0) || (~(t) < 0))
>
> Hmm... Not, I think, 100% portable in that on a ones' complement
> machine with "normal" negative zeros, C permits ~t to be zero (i.e. not
> < 0).
And it has undefined behavior on a two's-complement system if t is
INT_MIN.
I think it can fail if t is of an unsigned type that promotes to signed
int (I'll check that later).
I had assumed the argument should be a type rather than an expression of
the type.
--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
Working, but not speaking, for JetHead Development, Inc.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
[toc] | [prev] | [next] | [standalone]
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Date | 2015-05-18 21:15 +0100 |
| Message-ID | <87fv6tlk00.fsf@bsb.me.uk> |
| In reply to | #62214 |
Keith Thompson <kst-u@mib.org> writes: > Ben Bacarisse <ben.usenet@bsb.me.uk> writes: >> Morris Dovey <mrdovey@iedu.com> writes: >>> On 5/17/15 12:07 PM, asetofsymbols@gmail.com wrote: >>>> Is there any better way? >>> >>> Of course - look at the declaration! >>> >>> If you’re too lazy to do that, you could try (untested) >>> >>> #define IS_SIGNED(t) (((t) < 0) || (-(t) < 0) || (~(t) < 0)) >> >> Hmm... Not, I think, 100% portable in that on a ones' complement >> machine with "normal" negative zeros, C permits ~t to be zero (i.e. not >> < 0). > > And it has undefined behavior on a two's-complement system if t is > INT_MIN. How so? <snip> -- Ben.
[toc] | [prev] | [next] | [standalone]
| From | Keith Thompson <kst-u@mib.org> |
|---|---|
| Date | 2015-05-18 15:15 -0700 |
| Message-ID | <87oalh4jn5.fsf@kst-u.example.com> |
| In reply to | #62246 |
Ben Bacarisse <ben.usenet@bsb.me.uk> writes:
> Keith Thompson <kst-u@mib.org> writes:
>> Ben Bacarisse <ben.usenet@bsb.me.uk> writes:
>>> Morris Dovey <mrdovey@iedu.com> writes:
>>>> On 5/17/15 12:07 PM, asetofsymbols@gmail.com wrote:
>>>>> Is there any better way?
>>>>
>>>> Of course - look at the declaration!
>>>>
>>>> If you’re too lazy to do that, you could try (untested)
>>>>
>>>> #define IS_SIGNED(t) (((t) < 0) || (-(t) < 0) || (~(t) < 0))
>>>
>>> Hmm... Not, I think, 100% portable in that on a ones' complement
>>> machine with "normal" negative zeros, C permits ~t to be zero (i.e. not
>>> < 0).
>>
>> And it has undefined behavior on a two's-complement system if t is
>> INT_MIN.
>
> How so?
>
> <snip>
Never mind. (-(INT_MIN)) has undefined behavior on such a system, but
it's never evaluated because (INT_MIN) < 0 is true.
--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
Working, but not speaking, for JetHead Development, Inc.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
[toc] | [prev] | [next] | [standalone]
| From | glen herrmannsfeldt <gah@ugcs.caltech.edu> |
|---|---|
| Date | 2015-05-18 21:51 +0000 |
| Message-ID | <mjdmto$j40$1@speranza.aioe.org> |
| In reply to | #62214 |
Keith Thompson <kst-u@mib.org> wrote: > Ben Bacarisse <ben.usenet@bsb.me.uk> writes: (snip) >>> #define IS_SIGNED(t) (((t) < 0) || (-(t) < 0) || (~(t) < 0)) (snip) >> Hmm... Not, I think, 100% portable in that on a ones' complement >> machine with "normal" negative zeros, C permits ~t to be zero (i.e. not >> < 0). > And it has undefined behavior on a two's-complement system if t is > INT_MIN. -INT_MIN overflows on a twos-complement machine, but ~INT_MIN doesn't. But if ~INT_MIN was evaluated as -INT_MIN-1 then, yes, it would be undefined. No reason to do that, though. > I think it can fail if t is of an unsigned type that promotes to signed > int (I'll check that later). -- glen
[toc] | [prev] | [next] | [standalone]
| From | James Kuyper <jameskuyper@verizon.net> |
|---|---|
| Date | 2015-05-18 18:00 -0400 |
| Message-ID | <555A610E.3010802@verizon.net> |
| In reply to | #62249 |
On 05/18/2015 05:51 PM, glen herrmannsfeldt wrote: > Keith Thompson <kst-u@mib.org> wrote: >> Ben Bacarisse <ben.usenet@bsb.me.uk> writes: > (snip) >>>> #define IS_SIGNED(t) (((t) < 0) || (-(t) < 0) || (~(t) < 0)) > (snip) >>> Hmm... Not, I think, 100% portable in that on a ones' complement >>> machine with "normal" negative zeros, C permits ~t to be zero (i.e. not >>> < 0). > >> And it has undefined behavior on a two's-complement system if t is >> INT_MIN. > > -INT_MIN overflows on a twos-complement machine, but ~INT_MIN doesn't. More importantly, if t is INT_MIN, then (t)<0 doesn't overflow, has a value of 1, and therefore ensures that neither -(t) nor ~(t) ever gets evaluated.
[toc] | [prev] | [next] | [standalone]
| From | glen herrmannsfeldt <gah@ugcs.caltech.edu> |
|---|---|
| Date | 2015-05-18 14:37 +0000 |
| Message-ID | <mjctem$e7a$1@speranza.aioe.org> |
| In reply to | #62209 |
Ben Bacarisse <ben.usenet@bsb.me.uk> wrote: > Morris Dovey <mrdovey@iedu.com> writes: >> On 5/17/15 12:07 PM, asetofsymbols@gmail.com wrote: >>> Is there any better way? >> Of course - look at the declaration! >> If you???re too lazy to do that, you could try (untested) >> #define IS_SIGNED(t) (((t) < 0) || (-(t) < 0) || (~(t) < 0)) > Hmm... Not, I think, 100% portable in that on a ones' complement > machine with "normal" negative zeros, C permits ~t to be zero (i.e. not > < 0). Which reminds me, are there any C compilers for the CDC 6600? -- glen
[toc] | [prev] | [next] | [standalone]
| From | jacobnavia <jacob@jacob.remcomp.fr> |
|---|---|
| Date | 2015-05-18 17:09 +0200 |
| Message-ID | <mjcva1$364$1@dont-email.me> |
| In reply to | #62219 |
Le 18/05/2015 16:37, glen herrmannsfeldt a écrit : > Which reminds me, are there any C compilers for the CDC 6600? > > -- glen > There we go. Ahhhhh you remember back then? 1968? THOSE WERE THE DAYS MY FRIEND WE THOUGHT THEY WOULD NEVER END And again we start the specialty of this group... :-)
[toc] | [prev] | [next] | [standalone]
| From | glen herrmannsfeldt <gah@ugcs.caltech.edu> |
|---|---|
| Date | 2015-05-18 18:14 +0000 |
| Message-ID | <mjda5h$ho9$1@speranza.aioe.org> |
| In reply to | #62221 |
jacobnavia <jacob@jacob.remcomp.fr> wrote: > Le 18/05/2015 16:37, glen herrmannsfeldt a écrit : > >> Which reminds me, are there any C compilers for the CDC 6600? (snip) (or maybe cross compilers) > There we go. > Ahhhhh you remember back then? > 1968? http://livingcomputermuseum.cmail2.com/t/ViewEmail/t/8DABEE59AC800AD5/C0FC513325AE3FFF2540EF23F30FEDED -- glen
[toc] | [prev] | [next] | [standalone]
Page 1 of 4 [1] 2 3 4 Next page →
Back to top | Article view | comp.lang.c
csiph-web