Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #149926
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: Puzzling "implicit declaration" Warning |
| Date | 2020-02-10 16:42 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <87tv3yiech.fsf@bsb.me.uk> (permalink) |
| References | <WsmdnVL9ioPMhaDDnZ2dnUU7_83NnZ2d@giganews.com> <r1nefv$q60$1@dont-email.me> <o6qdnQd11fHXYN3DnZ2dnUU7_8zNnZ2d@giganews.com> <87blq6juu9.fsf@bsb.me.uk> <Swf0G.148429$0k2.52317@fx06.iad> |
scott@slp53.sl.home (Scott Lurndal) writes:
> Ben Bacarisse <ben.usenet@bsb.me.uk> writes:
>>Robbie Hatley <see.my.signature@for.my.contact.info> writes:
>>
>>> On 2020-02-08 3:00 PM, Les Cargill wrote:
>>>
>>>> Depending on context, you may want to use exp() ( as in
>>>> exp(log(10)*i) or pow(10,i). SFAIK, those are always there
>>>> and you don't need compiler flags.
>>>
>>> Interesting approach, using the rules for exp/log base change.
>>> Thanks for the tip.
>>>
>>> But in the end, for the purpose of THIS particular program,
>>> since what I really needed was unsigned-integer base-10 versions
>>> of log and exp, I ended up rolling my own. That allowed me to
>>> remove all typecasts, and still get the types I really want, and
>>> get rid of all "gnu extensions" and macros and warnings. I also
>>> got rid of the unnecessary array and second for loop in main():
>>>
>>> /* reverse.c */
>>> /* prints lexical reverse of unsigned-long-int argument */
>>> #include <stdio.h>
>>> #include <stdlib.h>
>>> unsigned long ten_to_the (unsigned x)
>>> {
>>> unsigned long y = 1;
>>> unsigned i;
>>> for ( i = 1U ; i <= x ; ++i ) y *= 10UL;
>>> return y;
>>> }
>>> unsigned log_ten_of (unsigned long x)
>>> {
>>> unsigned i;
>>> for ( i = 0U ; x >= 10UL ; ++i ) x /= 10UL;
>>> return i;
>>> }
>>> int main (int Beren, char *Luthien[])
>>> {
>>> unsigned long number;
>>> unsigned digits;
>>> unsigned i;
>>> if (2 != Beren) {exit(EXIT_FAILURE);}
>>> number = strtoul(Luthien[1], NULL, 10);
>>> digits = 1U + log_ten_of(number);
>>> for ( i = 0U ; i < digits ; ++i )
>>> {
>>> printf("%lu", (number/ten_to_the(i))%10);
>>> }
>>> exit(EXIT_SUCCESS);
>>> }
>>
>>It look like a lot of work for a relatively simple job:
>>
>> do printf("%lu", number % 10); while (number /= 10);
>>
>>By the way, you don't need the U suffix on these constants. C silently
>>promotes integer used in expressions. For example you did not have one
>>in the % 10 expressions and nothing went wrong.
>>
>
> On the other hand, it does help document the programmers intent, and
> indicates that the programmer was actually thinking about what was
> being written.
To me it indicates the programmer does not know what unsigned x = 1;
means in C. As such I might give the code slightly more scrutiny.
Did you worry that the programmer's intent was not clear enough because
there was no U on the 10? Were you about to post that one should be
added to the 10?
> There are cases where the suffix _is_ required, e.g.
>
> uint64_t fred;
>
> fred |= (1 << 33);
>
> for example.
Yes, I thought I'd said "in arithmetic expressions" but I hadn't (and I
suppose even that is not 100% clear).
--
Ben.
Back to comp.lang.c | Previous | Next — Previous in thread | Find similar | Unroll thread
Puzzling "implicit declaration" Warning Robbie Hatley <see.my.signature@for.my.contact.info> - 2020-02-06 23:57 -0800
Re: Puzzling "implicit declaration" Warning Jorgen Grahn <grahn+nntp@snipabacken.se> - 2020-02-07 08:53 +0000
Re: Puzzling "implicit declaration" Warning Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2020-02-07 02:12 -0800
Re: Puzzling "implicit declaration" Warning Robbie Hatley <see.my.signature@for.my.contact.info> - 2020-02-08 01:53 -0800
Re: Puzzling "implicit declaration" Warning Ben Bacarisse <ben.usenet@bsb.me.uk> - 2020-02-08 12:59 +0000
Re: Puzzling "implicit declaration" Warning Manfred <noname@invalid.add> - 2020-02-08 17:21 +0100
Re: Puzzling "implicit declaration" Warning Manfred <noname@invalid.add> - 2020-02-08 17:34 +0100
Re: Puzzling "implicit declaration" Warning Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2020-02-08 14:37 -0800
Re: Puzzling "implicit declaration" Warning scott@slp53.sl.home (Scott Lurndal) - 2020-02-08 18:39 +0000
Re: Puzzling "implicit declaration" Warning Robbie Hatley <see.my.signature@for.my.contact.info> - 2020-02-08 01:15 -0800
Re: Puzzling "implicit declaration" Warning chad <cdalten@gmail.com> - 2020-02-08 05:05 -0800
Re: Puzzling "implicit declaration" Warning Bart <bc@freeuk.com> - 2020-02-08 14:05 +0000
Re: Puzzling "implicit declaration" Warning Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2020-02-08 14:35 -0800
Re: Puzzling "implicit declaration" Warning Bart <bc@freeuk.com> - 2020-02-08 22:39 +0000
Re: Puzzling "implicit declaration" Warning Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2020-02-08 15:30 -0800
Re: Puzzling "implicit declaration" Warning David Brown <david.brown@hesbynett.no> - 2020-02-09 12:24 +0100
Re: Puzzling "implicit declaration" Warning Robbie Hatley <see.my.signature@for.my.contact.info> - 2020-02-09 23:42 -0800
Re: Puzzling "implicit declaration" Warning chad <cdalten@gmail.com> - 2020-02-10 05:34 -0800
Re: Puzzling "implicit declaration" Warning Ben Bacarisse <ben.usenet@bsb.me.uk> - 2020-02-10 16:12 +0000
Re: Puzzling "implicit declaration" Warning Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2020-02-10 11:14 -0800
Re: Puzzling "implicit declaration" Warning Jorgen Grahn <grahn+nntp@snipabacken.se> - 2020-02-11 07:06 +0000
Re: puzzling enragement by innocuous variable names Robbie Hatley <see.my.signature@for.my.contact.info> - 2020-09-10 19:47 -0700
Re: puzzling enragement by innocuous variable names Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2020-09-10 20:28 -0700
Re: puzzling enragement by innocuous variable names Peter 'Shaggy' Haywood <phaywood@alphalink.com.au> - 2020-09-13 14:57 +1000
Re: puzzling enragement by innocuous variable names gazelle@shell.xmission.com (Kenny McCormack) - 2020-09-15 17:58 +0000
Re: puzzling enragement by innocuous variable names Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2020-09-14 09:38 -0600
Re: Puzzling "implicit declaration" Warning James Kuyper <jameskuyper@alumni.caltech.edu> - 2020-02-11 00:21 -0500
Re: Puzzling "implicit declaration" Warning Les Cargill <lcargill99@comcast.com> - 2020-02-08 17:00 -0600
Re: Puzzling "implicit declaration" Warning Robbie Hatley <see.my.signature@for.my.contact.info> - 2020-02-09 22:50 -0800
Re: Puzzling "implicit declaration" Warning Ben Bacarisse <ben.usenet@bsb.me.uk> - 2020-02-10 16:00 +0000
Re: Puzzling "implicit declaration" Warning scott@slp53.sl.home (Scott Lurndal) - 2020-02-10 16:28 +0000
Re: Puzzling "implicit declaration" Warning Ben Bacarisse <ben.usenet@bsb.me.uk> - 2020-02-10 16:42 +0000
csiph-web