From: "Ankit Jain" <ankitjain1580@yahoo.com>
To: Jan-Benedict Glaw <jbglaw@lug-owl.de>
Cc: linux prg <linux-c-programming@vger.kernel.org>
Subject: Re: complex variable
Date: Wed, 8 Sep 2004 17:25:37 +0100 (BST) [thread overview]
Message-ID: <20040908162537.4782.qmail@web52906.mail.yahoo.com> (raw)
In-Reply-To: <20040908120658.GZ6985@lug-owl.de>
thanks....
but sorry sir i could not understand one thing which u
also clearly detected. it is "in" variable....its a
complex variable. this is somewhat not correct
complex x, *in = NULL;
but i wanted to ask if i want to use in as a 2D array
how to do that?
Ankit
--- Jan-Benedict Glaw <jbglaw@lug-owl.de> wrote:
> On Wed, 2004-09-08 11:59:48 +0200, Charlie Gordon
> <gmane@chqrlie.org>
> wrote in message <chml6d$kri$1@sea.gmane.org>:
>
> > > char szName[] = "test_data.dat";
> >
> > This is quite inefficient : declaring a local
> initialized array will produce
> > equivalent code to:
> >
> > char szName[sizeof("test_data.dat")];
> > memcpy(szName, "test_data.dat",
> sizeof("test_data.dat"));
> >
> > Whereas declaring a const char* fileName =
> "test_data.dat" will likely get
> > optimized by the compiler as not even storing the
> address into a local
> > variable.
>
> But remember there's a subtle difference between
>
> char filename[] = "/path/to/file";
>
> and
> char *filename = "/path/to/file";
>
>
> You may write to the first one (eg. later on use
> snprintf and friends
> with it), but you may not write to the 2nd one!
>
> > > if(NULL != (fp = fopen(szName, "rb")))
> >
> > This style is really ugly! there is really no
> advantage at combining the
> > assignment and the test:
> > fp = fopen(fileName, "rb");
> > if (fp != NULL) {
>
> That's somewhat personal style. Also notice that
> he's got the NULL at
> the beginnnig of the comparison, not at the end.
> That's something that
> seems to be tought these days, because assignments
> (if you mis-write
> "!=" as "=!" or "|=") will produce compile-time
> errors (NULL isn't a
> lvalue).
>
> > > {
> > > int N=32, i=0;
> > > complex x, *in = NULL;
> >
> > Are you sure about the complex type implementation
> ?
> > Are the real and imaginary parts float, double, of
> even long double ?
> > Reading them in bulk from the file is definitely
> not advisable, because of
> > this and because of byte ordering issues.
>
> For now, ignore the fact that in[] is wrongly
> accessed. It'll somewhat
> work (while being non-portable), I guess this code
> is here to only have
> a useful test program :-)
>
> > > if(NULL != (in=malloc(sizeof(complex)*N)))
> >
> > N as the uppercase name implies seems to be a
> constant in this code...
> > why not make it a const outside this block and
> declare in as a local array
> > instead of allocating it off the heap.
>
> A #define would have served, too, as well as a const
> int. Test code
> *needs* to be a bit ugliysh to qualify as test code
> :-)
>
> > > {
> > > if(N == fread(in, sizeof(complex),
> N, fp))
> > > {
> > > for(i=0; i< N; i++)
> > > printf("%lf\t", in[i]);
> >
> > What does this mean ?
> > C99 makes no difference between %f and %lf
> > I'm not sure what passing a complex to printf will
> actually do. Most lilely
> > not what you want and definitely not portable.
>
> Works for now, see the ugliness clause above. (Sure,
> you don't want that
> code in your program's final version, though...)
>
> MfG, JBG
>
> --
> Jan-Benedict Glaw jbglaw@lug-owl.de .
> +49-172-7608481 _ O _
> "Eine Freie Meinung in einem Freien Kopf | Gegen
> Zensur | Gegen Krieg _ _ O
> fuer einen Freien Staat voll Freier Bürger" | im
> Internet! | im Irak! O O O
> ret = do_actions((curr | FREE_SPEECH) &
> ~(NEW_COPYRIGHT_LAW | DRM | TCPA));
>
> ATTACHMENT part 2 application/pgp-signature
name=signature.asc
________________________________________________________________________
Yahoo! Messenger - Communicate instantly..."Ping"
your friends today! Download Messenger Now
http://uk.messenger.yahoo.com/download/index.html
-
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
next prev parent reply other threads:[~2004-09-08 16:25 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-09-07 15:37 complex variable Huber, George K RDECOM CERDEC STCD SRI
2004-09-07 16:05 ` Jan-Benedict Glaw
2004-09-08 9:59 ` Charlie Gordon
2004-09-08 12:06 ` Jan-Benedict Glaw
2004-09-08 16:25 ` Ankit Jain [this message]
2004-09-08 21:54 ` Charlie Gordon
2004-09-10 20:05 ` Jan-Benedict Glaw
2004-09-13 19:32 ` Charlie Gordon
2004-09-13 21:57 ` Jan-Benedict Glaw
2004-09-14 8:16 ` Charlie Gordon
-- strict thread matches above, loose matches on Subject: below --
2004-09-08 18:40 Huber, George K RDECOM CERDEC STCD SRI
2004-09-10 20:09 ` Jan-Benedict Glaw
[not found] <20040906134525.33692.qmail@web52908.mail.yahoo.com>
2004-09-06 16:25 ` Ankit Jain
2004-09-06 16:37 ` Jan-Benedict Glaw
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20040908162537.4782.qmail@web52906.mail.yahoo.com \
--to=ankitjain1580@yahoo.com \
--cc=jbglaw@lug-owl.de \
--cc=linux-c-programming@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).