Test me

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • raashid bhatt

    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
  • Richard Heathfield

    #2
    Re: Test me

    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];
    char *ptr[10]; // Means array of pointers to chars's
    Not quite. It's an array of ten pointers to char. I don't know what chars's
    means, but I hope it's a typo.
    which i can assing the following like this
    char str[][10] = {"string1", "string2"};
    No, that's an initialisation, not an assignment. It is, however, a legal
    initialisation of an array of two arrays of ten char.
    char (ptr*)[10] = str;
    No, that's a syntax error. You meant char (*ptr)[10] = str;
    or
    char (ptr*)[10] = &str; // Both are Equal
    Well, they're both wrong, if that's what you mean. &str has type
    char(*)[2][10]. If ptr were defined correctly, it would have a type of
    char(*)[10]. Not the same type by any means.
    and
    >
    char *ptr[10] = {"string1", "string1"};
    Yes, that's legal, although you should be very careful - you have reserved
    space only for the pointers, not the strings. As long as you're pointing
    at (but not changing) those string literals, you're fine - but if you want
    to change anything, you'll have to find some space to point at first.
    >
    char *ptr[10];
    >
    ptr[0] = "string1";
    ptr[1] = "string2";
    Yes, those are legal too.
    If i am Wrong Please correct me
    Some wrong, some right.

    --
    Richard Heathfield <http://www.cpax.org.uk >
    Email: -http://www. +rjh@
    Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
    "Usenet is a strange place" - dmr 29 July 1999

    Comment

    • Bill Reid

      #3
      Re: Test me


      Richard Heathfield <rjh@see.sig.in validwrote in message
      news:j86dndNX2a UbNjLVnZ2dnUVZ8 tHinZ2d@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
      incomprehensibl e aspect of an ostensible "programmin g 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(ch ar *html_buffer,si ze_t html_size,char **text_buffer) {

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

      if(isspace(*htm l_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 "programmin g language", it's
      a "platform" (AND a dessert topping AND a floor wax)...

      ---
      William Ernest Reid


      Comment

      • Bartc

        #4
        Re: Test me


        "Bill Reid" <hormelfree@hap pyhealthy.netwr ote in message
        news:qP4sk.1778 37$102.102026@b gtnsc05-news.ops.worldn et.att.net...
        >
        Richard Heathfield <rjh@see.sig.in validwrote in message
        news:j86dndNX2a UbNjLVnZ2dnUVZ8 tHinZ2d@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


        Comment

        • Pilcrow

          #5
          Re: Test me

          On Sun, 24 Aug 2008 03:45:26 GMT, "Bill Reid"
          <hormelfree@hap pyhealthy.netwr ote:
          >
          >Richard Heathfield <rjh@see.sig.in validwrote in message
          >news:j86dndNX2 aUbNjLVnZ2dnUVZ 8tHinZ2d@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
          >dereferencin g pointers in "C". NO non-lunatic has ever been able
          >to grasp the total non-logic of the topic, which is just one
          >incomprehensib le aspect of an ostensible "programmin g 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)...
          >
          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.

          Comment

          • Randy Howard

            #6
            Re: Test me

            On Mon, 25 Aug 2008 20:00:55 -0500, Pilcrow wrote
            (in article <evk6b4tue63rlh 0gmt839fi8hi665 rmddf@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.




            Comment

            • Richard Bos

              #7
              Re: Test me

              Pilcrow <pilcrow@pp.inf owrote:
              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

              Comment

              • Pilcrow

                #8
                Re: Test me

                On Tue, 26 Aug 2008 01:26:41 GMT, Randy Howard
                <FOOrandyhoward BAR@verizon.net wrote:
                >On Mon, 25 Aug 2008 20:00:55 -0500, Pilcrow wrote
                >(in article <evk6b4tue63rlh 0gmt839fi8hi665 rmddf@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.
                >
                I wonder what is the ratio of device drivers to other programs. And I,
                long ago, wrote a few device drivers for machines that are ancient
                history. But I didn't use either C or perl.

                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.

                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?


                Comment

                • Keith Thompson

                  #9
                  Re: Test me

                  Pilcrow <pilcrow@pp.inf owrites:
                  [...]
                  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_Keit h) 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"

                  Comment

                  • Pilcrow

                    #10
                    Re: Test me

                    On Tue, 26 Aug 2008 07:23:29 GMT, rlb@hoekstra-uitgeverij.nl (Richard
                    Bos) wrote:
                    >Pilcrow <pilcrow@pp.inf owrote:
                    >
                    >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
                    I would be happy to help you with anything you find puzzling in perl if
                    you'll help me with those $%^^%$^&# pointers in C.

                    Comment

                    • Pilcrow

                      #11
                      Re: Test me

                      On Tue, 26 Aug 2008 01:08:55 -0700, Keith Thompson <kst-u@mib.org>
                      wrote:
                      >Pilcrow <pilcrow@pp.inf owrites:
                      >[...]
                      >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?
                      In C, which proves he's a genius. Look at all the things he made easy
                      that are still hard in C. He deserves a medal. He'd have a knighthood
                      if he were a brit.

                      Comment

                      • Nick Keighley

                        #12
                        Re: Test me

                        On 26 Aug, 09:04, Pilcrow <pilc...@pp.inf owrote:
                        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 <evk6b4tue63rlh 0gmt839fi8hi665 rm...@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

                        Comment

                        • Richard Bos

                          #13
                          Re: Test me

                          Pilcrow <pilcrow@pp.inf owrote:
                          On Tue, 26 Aug 2008 07:23:29 GMT, rlb@hoekstra-uitgeverij.nl (Richard
                          Bos) wrote:
                          Pilcrow <pilcrow@pp.inf owrote:
                          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

                          Comment

                          • Willem

                            #14
                            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

                            Comment

                            • Scott

                              #15
                              Re: Test me

                              On Tue, 26 Aug 2008 01:04:50 -0700, in comp.lang.c, Pilcrow
                              <pilcrow@pp.inf owrote:
                              >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

                              Comment

                              Working...