Test me

Discussion in 'C Programming' started by raashid bhatt, Aug 23, 2008.

  1. 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
    raashid bhatt, Aug 23, 2008
    #1
    1. Advertising

  2. raashid bhatt

    Bill Reid Guest

    Richard Heathfield <> wrote in message
    news:...
    > 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
    Bill Reid, Aug 24, 2008
    #2
    1. Advertising

  3. raashid bhatt

    Bartc Guest

    "Bill Reid" <> wrote in message
    news:qP4sk.177837$...
    >
    > Richard Heathfield <> wrote in message
    > news:...
    >> 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
    Bartc, Aug 24, 2008
    #3
  4. raashid bhatt

    Randy Howard Guest

    On Mon, 25 Aug 2008 20:00:55 -0500, Pilcrow wrote
    (in article <>):

    > 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.
    Randy Howard, Aug 26, 2008
    #4
  5. raashid bhatt

    Richard Bos Guest

    Pilcrow <> 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
    Richard Bos, Aug 26, 2008
    #5
  6. Pilcrow <> 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) <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"
    Keith Thompson, Aug 26, 2008
    #6
  7. On 26 Aug, 09:04, Pilcrow <> wrote:
    > On Tue, 26 Aug 2008 01:26:41 GMT, Randy Howard
    > <> wrote:
    > >On Mon, 25 Aug 2008 20:00:55 -0500, Pilcrow wrote
    > >(in article <>):



    > >> 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
    Nick Keighley, Aug 26, 2008
    #7
  8. raashid bhatt

    Richard Bos Guest

    Pilcrow <> wrote:

    > On Tue, 26 Aug 2008 07:23:29 GMT, (Richard
    > Bos) wrote:
    > >Pilcrow <> 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
    Richard Bos, Aug 26, 2008
    #8
  9. raashid bhatt

    Willem Guest

    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
    Willem, Aug 26, 2008
    #9
  10. raashid bhatt

    Scott Guest

    On Tue, 26 Aug 2008 01:04:50 -0700, in comp.lang.c, Pilcrow
    <> 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
    Scott, Aug 26, 2008
    #10
  11. Pilcrow <> writes:
    [...]
    > 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.

    --
    Keith Thompson (The_Other_Keith) <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"
    Keith Thompson, Aug 26, 2008
    #11
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sting
    Replies:
    5
    Views:
    1,610
    Natty Gur
    Jun 8, 2004
  2. Robert Allan Schwartz
    Replies:
    7
    Views:
    364
    Marco Manfredini
    Aug 13, 2004
  3. Chris
    Replies:
    1
    Views:
    658
    Chris
    May 11, 2006
  4. Edvard Majakari
    Replies:
    4
    Views:
    673
    Edvard Majakari
    Feb 25, 2005
  5. Skybuck Flying

    Call oddities: &Test() vs &Test vs Test

    Skybuck Flying, Oct 4, 2009, in forum: C Programming
    Replies:
    1
    Views:
    682
    Skybuck Flying
    Oct 4, 2009
Loading...

Share This Page