Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| Path | csiph.com!optima2.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!1.eu.feeder.erje.net!news.swapon.de!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | Keith Thompson <kst-u@mib.org> |
| Newsgroups | comp.lang.c |
| Subject | Re: nested while loop computing triangular number - issues |
| Date | Sat, 11 Jul 2015 14:56:43 -0700 |
| Organization | None to speak of |
| Lines | 52 |
| Message-ID | <lnmvz2pdd0.fsf@kst-u.example.com> (permalink) |
| References | <8e9f29f8-a7d0-42c4-a146-2a0d0b937051@googlegroups.com> <87si8uu5tr.fsf@bsb.me.uk> <5abf1a27-ebbf-4c5d-89d9-e0b8fc6efd04@googlegroups.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=us-ascii |
| Injection-Info | mx02.eternal-september.org; posting-host="945944de09706c9b4e29b53c9d2efdc2"; logging-data="28182"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/gwlt8MnkVIP+aW26jTKE9" |
| User-Agent | Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) |
| Cancel-Lock | sha1:pDfE1/6OHmjpybo4KiD9k/KdRe0= sha1:JHirC2SwHr4OtZrwyIYdWx/yhhU= |
| Xref | csiph.com comp.lang.c:65348 |
Show key headers only | View raw
David Kleinecke <dkleinecke@gmail.com> writes:
[...]
> I have recently taken to writing this way - I repeat in my style:
>
> int main (void) {
> int n;
> int number;
> int triangular_number;
> int counter;
> #
> n = 1;
> counter = 1;
> triangular_number = 0;
The use of "#" (a null preprocessor directive) is odd. Perfectly legal,
but odd. I might use an ordinary comment like:
/******************/
> The reason is that I am looking at the local variables as members of
> an implict struct and that is the way I would write a struct, (I don't
> ever define more than one member per line in a struct and usually
> comment on what the member means on the same line.) I am thinking of
> making the implicit struct overt. I could then initialize but I really
> want to keep initialization in the code.
Individually declared objects can be can be initialized in place; struct
members can't. Thinking of a collection of objects as a struct might be
useful, but IMHO it's no reason to avoid the convenience of
in-place initialization.
> Given compiler control I could extend C to allow an assignment (not an
> initialization
> local_variables = {1, 0, 1, 0,};
> Maybe this ia already a known extension.
It's not an extension; it's a standard language feature, starting with
C99, called "compound literals".
local_variables = (struct foo){1, 0, 1, 0};
(Note that "(struct foo)" is not a cast; it's part of the syntax of the
compound literal.)
Of course if you insist on sticking to C90 you don't get to use things
like this.
--
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"
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
nested while loop computing triangular number - issues Alla _ <modelling.data@gmail.com> - 2015-07-11 06:31 -0700
Re: nested while loop computing triangular number - issues Alla _ <modelling.data@gmail.com> - 2015-07-11 06:52 -0700
Re: nested while loop computing triangular number - issues Siri Cruz <chine.bleu@yahoo.com> - 2015-07-11 07:07 -0700
Re: nested while loop computing triangular number - issues Alla _ <modelling.data@gmail.com> - 2015-07-11 07:27 -0700
Re: nested while loop computing triangular number - issues Siri Cruz <chine.bleu@yahoo.com> - 2015-07-11 08:19 -0700
Re: nested while loop computing triangular number - issues Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-07-11 15:28 +0100
Re: nested while loop computing triangular number - issues Alla _ <modelling.data@gmail.com> - 2015-07-11 08:01 -0700
Re: nested while loop computing triangular number - issues James Kuyper <jameskuyper@verizon.net> - 2015-07-11 12:24 -0400
Re: nested while loop computing triangular number - issues Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-07-11 21:24 +0100
Re: nested while loop computing triangular number - issues Alla _ <modelling.data@gmail.com> - 2015-07-12 09:35 -0700
Re: nested while loop computing triangular number - issues Keith Thompson <kst-u@mib.org> - 2015-07-12 11:55 -0700
Re: nested while loop computing triangular number - issues Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-07-12 22:14 +0100
Re: nested while loop computing triangular number - issues Alla _ <modelling.data@gmail.com> - 2015-07-13 08:05 -0700
Re: nested while loop computing triangular number - issues David Kleinecke <dkleinecke@gmail.com> - 2015-07-11 10:51 -0700
Re: nested while loop computing triangular number - issues Keith Thompson <kst-u@mib.org> - 2015-07-11 14:56 -0700
Re: nested while loop computing triangular number - issues David Kleinecke <dkleinecke@gmail.com> - 2015-07-12 09:32 -0700
Re: nested while loop computing triangular number - issues James Kuyper <jameskuyper@verizon.net> - 2015-07-12 13:19 -0400
Re: nested while loop computing triangular number - issues David Kleinecke <dkleinecke@gmail.com> - 2015-07-13 10:16 -0700
Re: nested while loop computing triangular number - issues Keith Thompson <kst-u@mib.org> - 2015-07-12 11:48 -0700
Re: nested while loop computing triangular number - issues James Kuyper <jameskuyper@verizon.net> - 2015-07-12 15:23 -0400
Re: nested while loop computing triangular number - issues Tim Rentsch <txr@alumni.caltech.edu> - 2015-07-15 11:02 -0700
Re: nested while loop computing triangular number - issues Keith Thompson <kst-u@mib.org> - 2015-07-15 13:19 -0700
Re: nested while loop computing triangular number - issues Tim Rentsch <txr@alumni.caltech.edu> - 2015-07-20 11:01 -0700
Re: nested while loop computing triangular number - issues Alla _ <modelling.data@gmail.com> - 2015-07-11 08:45 -0700
csiph-web