Test me

R

raashid bhatt

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
 
B

Bill Reid

Richard Heathfield said:
raashid bhatt said:

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)...
 
B

Bartc

Bill Reid said:
Richard Heathfield said:
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.
 
R

Randy Howard

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.
 
R

Richard Bos

Pilcrow said:
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
 
K

Keith Thompson

Pilcrow said:
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?
 
N

Nick Keighley

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



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

quite high in numbers of programs I imagine.

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
 
R

Richard Bos

Pilcrow said:
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
 
W

Willem

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
 
S

Scott

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
 
K

Keith Thompson

Pilcrow said:
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.

You can count on any C compiler you're likely to encounter to conform
(in some mode) to the C90 standard, and probably to the 1995 amendment
(which added a few minor features). Most C compilers these days
implement *some* of the features that were added in the C99 standard,
but very few implement all of them.

If you want the maximum possible portability, you can stick to the
common subset of C90 and C99, which basically means using C90 but
avoiding implicit int and making sure you have declarations for all
your functions. C99 doesn't require the use of prototypes, but you
should always use them anyway.

If portability is less of a concern for you, you can use whatever
extensions and/or C99 features your compiler offers.
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?

If you haven't already, read sections 4, 5, and 6 of the comp.lang.c
FAQ, <http://www.c-faq.com/>. Read K&R2 as well. H&S5 ("C: A
Reference Manual", 5th edition, by Harbison and Steele) is an
excellent reference, but not intended to be a tutorial.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top