Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C Programming (http://www.velocityreviews.com/forums/f42-c-programming.html)
-   -   Test me (http://www.velocityreviews.com/forums/t631952-test-me.html)

raashid bhatt 08-23-2008 06:08 AM

Test me
 
From 5 -6 day i have been learning c pointers i think i have learned
pretty much Please Check me if i am right

char (ptr*)[10]; // Means a pointer to array of 10 chars
char *ptr[10]; // Means array of pointers to chars's

which i can assing the following like this
char str[][10] = {"string1", "string2"};
char (ptr*)[10] = str;

or
char (ptr*)[10] = &str; // Both are Equal

and

char *ptr[10] = {"string1", "string1"};

char *ptr[10];

ptr[0] = "string1";
ptr[1] = "string2";

If i am Wrong Please correct me

Bill Reid 08-24-2008 03:45 AM

Re: Test me
 

Richard Heathfield <rjh@see.sig.invalid> wrote in message
news:j86dndNX2aUbNjLVnZ2dnUVZ8tHinZ2d@bt.com...
> raashid bhatt said:
>
> > From 5 -6 day i have been learning c pointers i think i have learned
> > pretty much Please Check me if i am right


Quit now while you still have some semblance of your sanity.
It's completely friggin' impossible to learn all the bass-ackwards
and semi-sideways inconsistent methods of declaring and
dereferencing pointers in "C". NO non-lunatic has ever been able
to grasp the total non-logic of the topic, which is just one
incomprehensible aspect of an ostensible "programming language"
that was obviously actually designed as a cruel joke on anybody
who would attempt to use it (I can just hear the uber-techno-trolls
K&R sniggering about it now)...

> > char (ptr*)[10]; // Means a pointer to array of 10 chars

>
> No, it's a syntax error. You meant:
>
> char (*ptr)[10];


Oh sure, but WHY??!??!! I mean it just looks so weird...

Or consider trying to dereference a pointer to an array of characters
passed to a function:

size_t html_to_text(char *html_buffer,size_t html_size,char **text_buffer) {

/* ...other insanity snipped... */

if(isspace(*html_char)) {

(*text_buffer)[text_size++]=' ';
num_spaces++;
}

/* ...more craziness elided... */

(*text_buffer)[text_size++]='\0';

return text_size;
}

Completely inexplicable, but just try this:

*text_buffer[text_size++]='\0';

....and watch the blue screen of death appear...

Really dude, give up, everybody else uses Java(TM), you should
too, and even better it's not actually a "programming language", it's
a "platform" (AND a dessert topping AND a floor wax)...

---
William Ernest Reid



Bartc 08-24-2008 10:06 AM

Re: Test me
 

"Bill Reid" <hormelfree@happyhealthy.net> wrote in message
news:qP4sk.177837$102.102026@bgtnsc05-news.ops.worldnet.att.net...
>
> Richard Heathfield <rjh@see.sig.invalid> wrote in message
> news:j86dndNX2aUbNjLVnZ2dnUVZ8tHinZ2d@bt.com...
>> raashid bhatt said:
>>
>> > From 5 -6 day i have been learning c pointers i think i have learned
>> > pretty much Please Check me if i am right


>> > char (ptr*)[10]; // Means a pointer to array of 10 chars

>>
>> No, it's a syntax error. You meant:
>>
>> char (*ptr)[10];

>
> Oh sure, but WHY??!??!! I mean it just looks so weird...


You mean, it looks weird because you might expect a (pointer to (an array of
10 chars)) to look like:

char *(ptr[10]);

(and not *ptr looks weird compared to ptr*)?

I agree. But not a reason to dismiss an entire language (especially as there
is no ready alternative). There are ways to get around these back-to-front
and inside-out type declarations.

--
Bartc



Randy Howard 08-26-2008 01:26 AM

Re: Test me
 
On Mon, 25 Aug 2008 20:00:55 -0500, Pilcrow wrote
(in article <evk6b4tue63rlh0gmt839fi8hi665rmddf@4ax.com>):

> That's about what I've concluded too. As far as I can see, the only
> advantage C has over Perl is speed. Speed, that is, of excution, not of
> total developement. Perl has the advantage of being developed by a
> genius who cares about his product being usable. When Perl 6 is finally
> out C will no longer have any adantage.


Let us know when you write a device driver for a raid controller in
perl.





Richard Bos 08-26-2008 07:23 AM

Re: Test me
 
Pilcrow <pilcrow@pp.info> wrote:

> That's about what I've concluded too. As far as I can see, the only
> advantage C has over Perl is speed.


And readability. And debuggability.

> Speed, that is, of excution, not of total developement. Perl has the
> advantage of being developed by a genius who cares about his product
> being usable.


Usable? Pull the other one, it's got bells on.

All programming languages are tools of Cthulhu, except Perl, which is
worse. Other languages have tentacles; Perl _is_ tentacles.

Richard

Keith Thompson 08-26-2008 08:08 AM

Re: Test me
 
Pilcrow <pilcrow@pp.info> writes:
[...]
> That's about what I've concluded too. As far as I can see, the only
> advantage C has over Perl is speed. Speed, that is, of excution, not of
> total developement. Perl has the advantage of being developed by a
> genius who cares about his product being usable. When Perl 6 is finally
> out C will no longer have any adantage.


A genius who implemented Perl in what language?

--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"

Nick Keighley 08-26-2008 08:43 AM

Re: Test me
 
On 26 Aug, 09:04, Pilcrow <pilc...@pp.info> wrote:
> On Tue, 26 Aug 2008 01:26:41 GMT, Randy Howard
> <FOOrandyhoward...@verizon.net> wrote:
> >On Mon, 25 Aug 2008 20:00:55 -0500, Pilcrow wrote
> >(in article <evk6b4tue63rlh0gmt839fi8hi665rm...@4ax.com>):



> >> That's about what I've concluded too. *As far as I can see, the only
> >> advantage C has over Perl is speed. *Speed, that is, of excution, not of
> >> total developement. *Perl has the advantage of being developed by a
> >> genius who cares about his product being usable.


good grief. Thank goodness it didn't try and make it unusable!
:-)

> >> *When Perl 6 is finally
> >> out C will no longer have any adantage.


portability.


> >Let us know when you write a device driver for a raid controller in
> >perl.

>
> I wonder what is the ratio of device drivers to other programs. *


quite high in numbers of programs I imagine.

<snip>

> I have been programming for some years, but only recently trying to
> acquire C. *It seems that there are several flavors and standards, which
> are sometimes followed by different compilers, and othertimes not. *But
> nothing that you can really count on.


C has a stable standard (the ISO C 1989 and 1990 (c89)). Writing code
to
this standard leads to highly portable code. Portable to a *huge*
range
of architectures.

The ISO C 1999 (c99) is less widely implemented and consequently less
portable.
(This may lead to a flame-fest but it is the plain unvarnished truth,
check the archives for comp.lang.c).

Most compilers implement a superset of c89.

I admit perl is different in that it really only has a single
implementation. If perl is available on a machine then your
(reasonably well written) program will run on it. If perl
doesn't run, well tough.


> Then there is (are?) pointers. *I have just about figured out that * is
> used in different ways at different times, but still can't get it
> straight in my head. *Whenever I use a * it's a gamble whether it's the
> right way or not.
>
> Perhaps one of you kind folk would point me to a good thorough treatment
> on pointers in C?


"The C programming Language" ed2 aka K&R


--
Nick Keighley


Richard Bos 08-26-2008 11:15 AM

Re: Test me
 
Pilcrow <pilcrow@pp.info> wrote:

> On Tue, 26 Aug 2008 07:23:29 GMT, rlb@hoekstra-uitgeverij.nl (Richard
> Bos) wrote:
> >Pilcrow <pilcrow@pp.info> wrote:
> >
> >> Speed, that is, of excution, not of total developement. Perl has the
> >> advantage of being developed by a genius who cares about his product
> >> being usable.

> >
> >Usable? Pull the other one, it's got bells on.
> >
> >All programming languages are tools of Cthulhu, except Perl, which is
> >worse. Other languages have tentacles; Perl _is_ tentacles.

>
> I would be happy to help you with anything you find puzzling in perl if
> you'll help me with those $%^^%$^&# pointers in C.


Unless you are capable of completely eradicating the There's More Than
One Way To Do It, So We'll Use Them All Within A Single Line, By The
Great Narlathotep! mentality from the Perl community, I fear that you
are on a hiding to nothing there.

Richard

Willem 08-26-2008 11:24 AM

Re: Test me
 
Richard Bos wrote:
) Unless you are capable of completely eradicating the There's More Than
) One Way To Do It, So We'll Use Them All Within A Single Line, By The
) Great Narlathotep! mentality from the Perl community, I fear that you
) are on a hiding to nothing there.

You're confusing perl hacking and perl programming,
and this mentality is not unique to perl. Refer to the IOCCC.

:-)


SaSW, Willem
--
Disclaimer: I am in no way responsible for any of the statements
made in the above text. For all I know I might be
drugged or something..
No I'm not paranoid. You all think I'm paranoid, don't you !
#EOT

Scott 08-26-2008 03:37 PM

Re: Test me
 
On Tue, 26 Aug 2008 01:04:50 -0700, in comp.lang.c, Pilcrow
<pilcrow@pp.info> wrote:

>Then there is (are?) pointers. I have just about figured out that * is
>used in different ways at different times, but still can't get it
>straight in my head. Whenever I use a * it's a gamble whether it's the
>right way or not.
>
>Perhaps one of you kind folk would point me to a good thorough treatment
>on pointers in C?


I found C relatively easy to learn, but I think it's because I was
well-versed in assembler long before I tried C. Pointers are hard to learn,
but once you understand them, using a language without them feels very
constricting.

-Scott


All times are GMT. The time now is 01:10 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.