Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!border3.nntp.dca.giganews.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!nntp.earthlink.com!news.earthlink.com.POSTED!not-for-mail |
|---|---|
| NNTP-Posting-Date | Tue, 27 Sep 2011 20:14:08 -0500 |
| Message-ID | <4E8274E0.7965@mindspring.com> (permalink) |
| Date | Tue, 27 Sep 2011 21:14:08 -0400 |
| From | pete <pfiland@mindspring.com> |
| Reply-To | pfiland@mindspring.com |
| Organization | PF |
| X-Mailer | Mozilla 3.04Gold (WinNT; I) |
| MIME-Version | 1.0 |
| Newsgroups | comp.lang.c |
| Subject | Re: To use Perl like conditional assignment in C |
| References | <a2b7378d-3156-4f3c-ad6a-1bf14330d993@5g2000yqo.googlegroups.com> <4E7DC3AA.427D@mindspring.com> <9e7n5aF5qvU1@mid.individual.net> <4E7F224B.4BA0@mindspring.com> <9ecvitFmu0U2@mid.individual.net> |
| Content-Type | text/plain; charset=us-ascii |
| Content-Transfer-Encoding | 7bit |
| Lines | 74 |
| X-Usenet-Provider | http://www.giganews.com |
| NNTP-Posting-Host | 4.154.219.202 |
| X-Trace | sv3-FaJrH6Q2//SbS6a8B8tkkkV/fWqISM0gbj9IBxn93rXcM4JENlTnVeLVuZGZR7kc+ZfTXBTugU7e4IA!BeOGQCP6vQw89E7RgYGoDzB9YBZ411rjzMfJM0CBZEFXChBaJ/bc/7axR9c7LzJlPyrTLmtMD6vw!7q3y737rJ2U= |
| X-Abuse-and-DMCA-Info | Please be sure to forward a copy of ALL headers |
| X-Abuse-and-DMCA-Info | Otherwise we will be unable to process your complaint properly |
| X-Postfilter | 1.3.40 |
| X-Original-Bytes | 3506 |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.c:11034 |
Show key headers only | View raw
Uno wrote:
>
> On 9/25/2011 5:44 AM, pete wrote:
> > Uno wrote:
> >>
> >> On 9/24/2011 4:48 AM, pete wrote:
> >>> Ya Shou wrote:
> >>>>
> >>>> Hello,
> >>>>
> >>>> I want to assign an uncertain value to a variable, this variable with
> >>>> values in the configuration file, reads the configuration file
> >>>> through a function to return to the read configuration value, if not
> >>>> configured or the value of non-compliance, will return 0 for failure,
> >>>> when this, I will to give it a default value assigned.
> >>>>
> >>>> However, I found it seem impossible to achieve this in C, but much
> >>>> easier to implement in Perl, see below:
> >>>>
> >>>> cfgval = loadConfig () || DEFAULT_VAL;
> >>>>
> >>>> In C '||' operator does not return the value of the expression which
> >>>> is true, but returns 1 or 0, so that I can not be used in a similar
> >>>> way. I considered a program in C is:
> >>>>
> >>>> cfgval = loadConfig ()? loadConfig (): DEFAULT_VAL;
> >>>>
> >>>> And however, this approach to involve a duplication of code, it is
> >>>> ugly, the other will call loadConfig function twice, inefficient and
> >>>> likely to cause unnecessary accidents.
> >>>>
> >>>> Of course, if / else statement can achieve this functionality, but
> >>>> this method requires an additional variable, and not look simple. As
> >>>> follows:
> >>>>
> >>>> int loadval = loadConfig ();
> >>>> if (loadval! = 0) {
> >>>> cfgval = loadval;
> >>>> } else {
> >>>> cfgval = DEFAULT_VAL;
> >>>> }
> >>>>
> >>>> Or
> >>>>
> >>>> int loadval;
> >>>> cfgval = (loadval! = 0)? loadval: DEFAULT_VAL;
> >>>>
> >>>> I would like to ask you is, in this case, there is nothing more
> >>>> beautiful realization?
> >>>
> >>> cfgval = loadConfig ();
> >>> if (cfgval == 0) {
> >>> cfgval = DEFAULT_VAL;
> >>> }
> >>>
> >>
> >> pete,
> >>
> >> you just posted another syntax other than c tonight in clc; watch it,
> >> there, revolutionary.
> >
> > I don't think that I did that.
> >
>
> Because perl is a child of c,
> or that if you thought what you posted was
> C, it wouldn't be syntactical?
I just posted some C code.
If it also happens to be some other code,
I don't know anything about it.
--
pete
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
To use Perl like conditional assignment in C Ya Shou <shouyatf@gmail.com> - 2011-09-24 04:06 -0700
Re: To use Perl like conditional assignment in C Willem <willem@toad.stack.nl> - 2011-09-24 11:13 +0000
Re: To use Perl like conditional assignment in C pete <pfiland@mindspring.com> - 2011-09-24 07:48 -0400
Re: To use Perl like conditional assignment in C Uno <merrilljensen@q.com> - 2011-09-24 21:58 -0700
Re: To use Perl like conditional assignment in C pete <pfiland@mindspring.com> - 2011-09-25 08:44 -0400
Re: To use Perl like conditional assignment in C Uno <merrilljensen@q.com> - 2011-09-26 21:52 -0700
Re: To use Perl like conditional assignment in C pete <pfiland@mindspring.com> - 2011-09-27 21:14 -0400
Re: To use Perl like conditional assignment in C Keith Thompson <kst-u@mib.org> - 2011-09-27 19:56 -0700
Re: To use Perl like conditional assignment in C Nick Keighley <nick_keighley_nospam@hotmail.com> - 2011-09-25 06:53 -0700
Re: To use Perl like conditional assignment in C "J. J. Farrell" <jjf@bcs.org.uk> - 2011-09-26 04:40 +0100
Re: To use Perl like conditional assignment in C Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-09-24 09:04 -0400
Re: To use Perl like conditional assignment in C Willem <willem@toad.stack.nl> - 2011-09-24 14:06 +0000
Re: To use Perl like conditional assignment in C Ya Shou <shouyatf@gmail.com> - 2011-09-26 21:10 -0700
Re: To use Perl like conditional assignment in C Jorgen Grahn <grahn+nntp@snipabacken.se> - 2011-09-29 22:08 +0000
Re: To use Perl like conditional assignment in C "BartC" <bc@freeuk.com> - 2011-09-26 01:37 +0100
csiph-web