Source

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Default User

    #16
    Re: Source

    Bill Cunningham wrote:
    [color=blue]
    > Then C is an object language.[/color]


    C has objects. It, with some pain, can do object-oriented programming.
    OO is not a natural idiom for C programming. If you want to do OO, there
    are better languages.



    Brian Rodenborn

    Comment

    • Arthur J. O'Dwyer

      #17
      Re: Source


      On Thu, 9 Oct 2003, Ashish wrote:[color=blue]
      >[color=green][color=darkred]
      > > > "Joona I Palaste" <palaste@cc.hel sinki.fi> wrote...
      > > >> Bill Cunningham <nospam@net.net > scribbled the following:
      > > >>
      > > >> > struct GUID (int x,int y);
      > > >>
      > > >> This is a syntax error in C. Would you be wanting comp.lang.c++?[/color][/color]
      >
      > I think he meant struct GUID {int x, int y};[/color]

      That's still a syntax error in C.
      But in C++, one can legally write

      struct GUID
      {
      GUID (int x, int y); // <-- this line
      };

      which is very close to what Bill wrote.
      In C, one can legally write

      struct GUID { int x; int y; };

      which is also similar (but of course
      means something completely different).

      -Arthur

      Comment

      • Severian

        #18
        Re: Source

        On 9 Oct 2003 20:48:02 GMT, "Mark A. Odell" <nospam@embedde dfw.com>
        wrote:
        [color=blue]
        >Sheldon Simms <sheldonsimms@y ahoo.com> wrote in
        >news:pan.2003. 10.09.20.13.51. 785991@yahoo.co m:
        >[color=green][color=darkred]
        >>> But if I actually wanted a GUID object, and not a pointer to one,
        >>> initialzed to zero I'd need to write:
        >>>
        >>> struct GUID guid = { 0 };[/color]
        >>
        >> Ok.
        >>[color=darkred]
        >>> or
        >>>
        >>> struct GUID guid;
        >>> memset(guid, 0, sizeof guid);[/color]
        >>
        >> This isn't a very good idea.[/color]
        >
        >Are you concerned about traps? I suppose this may not be fully portable
        >but I admit I am guilty of doing this quite often.[/color]

        I used to do that too (back in the day using an old VAX C compiler),
        but I always use the first form now. It's simpler, cleaner and works
        just fine.

        - Sev

        Comment

        • Mark McIntyre

          #19
          Re: Source

          On Thu, 9 Oct 2003 15:51:02 -0400, in comp.lang.c , "Bill Cunningham"
          <nospam@net.net > wrote:
          [color=blue]
          >
          >"Mark A. Odell" <nospam@embedde dfw.com> wrote in message
          >news:Xns940F9C 5FEE68Copyright MarkOdell@130.1 33.1.4...[color=green]
          >>
          >> But if I actually wanted a GUID object,
          >>[/color]
          >Then C is an object language.[/color]

          C defines "Object" thus.
          3.14
          1 object
          region of data storage in the execution environment, the contents of
          which can represent values

          Note that this has NOTHING to do with being object-oriented which is I
          suspect what you meant.
          --
          Mark McIntyre
          CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
          CLC readme: <http://www.angelfire.c om/ms3/bchambless0/welcome_to_clc. html>


          ----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
          http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
          ---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---

          Comment

          • Mark McIntyre

            #20
            Re: Source

            On Thu, 09 Oct 2003 21:15:32 GMT, in comp.lang.c , Matt Gregory
            <bleah-no-more-spam@earthlink. net> wrote:
            [color=blue]
            >Mark A. Odell wrote:
            >[color=green]
            >> Sheldon Simms <sheldonsimms@y ahoo.com> wrote in
            >> news:pan.2003.1 0.09.20.13.51.7 85991@yahoo.com :
            >>[color=darkred]
            >>>>struct GUID guid;
            >>>>memset(guid , 0, sizeof guid);
            >>>
            >>>This isn't a very good idea.[/color]
            >>
            >>
            >> Are you concerned about traps? I suppose this may not be fully portable
            >> but I admit I am guilty of doing this quite often.[/color]
            >
            >What's wrong with it?[/color]

            all-bits-zero might be a trap representation or other invalid value
            for one of the data types within the GUID structure. For instance,
            all-bits-zero might represent "Not a Number" for floating point, so
            that if you later on tried to read it, you'd possibly coredump.
            --
            Mark McIntyre
            CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
            CLC readme: <http://www.angelfire.c om/ms3/bchambless0/welcome_to_clc. html>


            ----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
            http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
            ---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---

            Comment

            • David Rubin

              #21
              Re: Source

              Ashish wrote:
              [color=blue][color=green][color=darkred]
              > > >> >> > What does the following code mean?
              > > >> >>
              > > >> >> > struct GUID *guid ={0};
              > > >> >>
              > > >> >> It initialises a pointer to struct GUID, whatever struct GUID is.
              > > >> >> The pointer is currently not pointing at any struct GUID.
              > > >> >>
              > > >> > A struct GUID then, how would one write it. The GUID comes from MS's
              > > >> > COM.
              > > >>
              > > >> > struct GUID (int x,int y);[/color][/color][/color]

              It doesn't matter what struct GUID is because guid is only a *pointer*.
              You are just initializing a pointer to the value 0. This is the same as

              struct GUID *guid = 0;

              or

              int *p = 0;

              for that matter.

              [snip][color=blue][color=green]
              > > If it's C then your compiler will choke on:
              > > struct GUID (int x, int y);[/color]
              >
              > I think he meant struct GUID {int x, int y};[/color]

              That is still a syntax error. ITYM

              struct GUID {int x; int y;};

              However, this is a moot point.

              /david

              --
              Andre, a simple peasant, had only one thing on his mind as he crept
              along the East wall: 'Andre, creep... Andre, creep... Andre, creep.'
              -- unknown

              Comment

              • Bill Cunningham

                #22
                Re: Source


                [color=blue][color=green][color=darkred]
                > > >> >> > What does the following code mean?
                > > >> >>
                > > >> >> > struct GUID *guid ={0};
                > > >> >>
                > > >> >> It initialises a pointer to struct GUID, whatever struct GUID is.[/color][/color]
                > The[color=green][color=darkred]
                > > >> >> pointer is currently not pointing at any struct GUID.
                > > >> >>
                > > >> > A struct GUID then, how would one write it. The GUID comes from[/color][/color][/color]
                MS's[color=blue][color=green][color=darkred]
                > > > COM.
                > > >>
                > > >> > struct GUID (int x,int y);
                > > >>
                > > >> This is a syntax error in C. Would you be wanting comp.lang.c++?[/color]
                > >
                > > Did you read this bit?
                > >[color=darkred]
                > > >> > The GUID struct is already defined in COM but that doesn't help me[/color][/color]
                > learn[color=green][color=darkred]
                > > > the
                > > >> > concept of struct. What I've seen looks like data type declarations[/color][/color]
                > and[color=green][color=darkred]
                > > > no
                > > >> > functions.
                > > >>
                > > >> > struct A{
                > > >> > int a;
                > > >> > char b;
                > > >> > double c;};
                > > >>
                > > >> Structs are different things in C and C++. Pick a language. If it's
                > > >> really C then reply again and I will explain what structs are in C.[/color]
                > >[color=darkred]
                > > > C of course. This is clc. What I was saying was that I never see[/color][/color]
                > functions[color=green][color=darkred]
                > > > in structs. Just declared data types.[/color]
                > >
                > > If it's C then your compiler will choke on:
                > > struct GUID (int x, int y);[/color]
                >
                > I think he meant struct GUID {int x, int y};
                >
                >[color=green]
                > > The fact that there aren't any functions declared inside that struct
                > > GUID doesn't help. It won't magically make the C compiler accept syntax
                > > errors.
                > > Therefore I still suspect your code is really C++.
                > >[/color][/color]
                What I'm really wanting to know I guess is how structs work and how to use
                them. I used the GUID example.
                For example.
                typedef struct A{
                int a;
                double b;}/* sometimes a term */ ;
                and I've seen struct A without the typedef.
                What's the difference with and w/o the typedef? The structs hold data I can
                see. How are they called? Is data all they hold?

                This and pointers are the major sticking points for me with C. And when
                there are bunches of parenthesis such as (((((*c))))))). That's confusing.
                It looks like a time warp. Unions I rarely see.

                Bill





                -----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
                http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
                -----== Over 100,000 Newsgroups - 19 Different Servers! =-----

                Comment

                • Ashish

                  #23
                  Re: Source


                  "Arthur J. O'Dwyer" <ajo@nospam.and rew.cmu.edu> wrote in message
                  news:Pine.LNX.4 .58-035.03100917370 40.20686@unix45 .andrew.cmu.edu ...[color=blue]
                  >
                  > On Thu, 9 Oct 2003, Ashish wrote:[color=green]
                  > >[color=darkred]
                  > > > > "Joona I Palaste" <palaste@cc.hel sinki.fi> wrote...
                  > > > >> Bill Cunningham <nospam@net.net > scribbled the following:
                  > > > >>
                  > > > >> > struct GUID (int x,int y);
                  > > > >>
                  > > > >> This is a syntax error in C. Would you be wanting comp.lang.c++?[/color]
                  > >
                  > > I think he meant struct GUID {int x, int y};[/color]
                  >
                  > That's still a syntax error in C.
                  > But in C++, one can legally write
                  >[/color]

                  Sorry, I meant struct GUID {int x; int y;};

                  [color=blue]
                  > struct GUID
                  > {
                  > GUID (int x, int y); // <-- this line
                  > };
                  >
                  > which is very close to what Bill wrote.
                  > In C, one can legally write
                  >
                  > struct GUID { int x; int y; };
                  >
                  > which is also similar (but of course
                  > means something completely different).
                  >
                  > -Arthur[/color]


                  Comment

                  • Jack Klein

                    #24
                    Re: Source

                    On Thu, 09 Oct 2003 23:50:41 +0100, Mark McIntyre
                    <markmcintyre@s pamcop.net> wrote in comp.lang.c:
                    [color=blue]
                    > On Thu, 9 Oct 2003 15:51:02 -0400, in comp.lang.c , "Bill Cunningham"
                    > <nospam@net.net > wrote:
                    >[color=green]
                    > >
                    > >"Mark A. Odell" <nospam@embedde dfw.com> wrote in message
                    > >news:Xns940F9C 5FEE68Copyright MarkOdell@130.1 33.1.4...[color=darkred]
                    > >>
                    > >> But if I actually wanted a GUID object,
                    > >>[/color]
                    > >Then C is an object language.[/color]
                    >
                    > C defines "Object" thus.
                    > 3.14
                    > 1 object
                    > region of data storage in the execution environment, the contents of
                    > which can represent values
                    >
                    > Note that this has NOTHING to do with being object-oriented which is I
                    > suspect what you meant.[/color]

                    ....and C++ describes it equivalently, using more words:

                    1.8 The C++ object model
                    1 The constructs in a C++ program create, destroy, refer to, access,
                    and manipulate objects. An object is a region of storage. [Note: A
                    function is not an object, regardless of whether or not it occupies
                    storage in the way that objects do. ] An object is created by a
                    definition (3.1), by a new expression
                    (5.3.4) or by the implementation (12.2) when needed. The properties of
                    an object are determined when the object is created.
                    An object can have a name (clause 3). An object has a storage duration
                    (3.7) which influences its lifetime
                    (3.8). An object has a type (3.9). The term object type refers to the
                    type with which the object is created.

                    --
                    Jack Klein
                    Home: http://JK-Technology.Com
                    FAQs for
                    comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
                    comp.lang.c++ http://www.parashift.com/c++-faq-lite/
                    alt.comp.lang.l earn.c-c++ ftp://snurse-l.org/pub/acllc-c++/faq

                    Comment

                    • Richard Heathfield

                      #25
                      Re: Source

                      Bill Cunningham wrote:
                      [color=blue]
                      > What I'm really wanting to know I guess is how structs work and how to use
                      > them.[/color]

                      They work the same way ints work. They're just types, that's all.
                      [color=blue]
                      > I used the GUID example.
                      > For example.
                      > typedef struct A{
                      > int a;
                      > double b;}/* sometimes a term */ ;[/color]

                      This is a syntax error.

                      typedef struct A{
                      int a;
                      double b;} A;

                      would not be a syntax error, however. Here is the typedef again, this time
                      on a single line:

                      typedef struct A{ int a; double b;} A;

                      Here it is again, perhaps slightly less confusingly:

                      typedef struct A_tag { int a; double b;} A;


                      There are two parts here, which I'll separate out vertically for you:

                      xxxxxxx struct A_tag { int a; double b;} xx

                      typedef xxxxxxxxxxxxxxx xxxxxxxxxxxxxxx xx A;

                      There's the typedef (something-as) A, and there's the struct definition.

                      Put them together, and you are defining A as an alias for struct A_tag.
                      [color=blue]
                      > and I've seen struct A without the typedef.
                      > What's the difference with and w/o the typedef?[/color]

                      typedef creates a new synonym for an existing type. So, once the compiler
                      has seen the above example, you can use A wherever you would previously
                      have used struct A_tag - if you wish. To confuse matters, the tag is
                      allowed to be the same as the new type.
                      [color=blue]
                      > The structs hold data I
                      > can see. How are they called?[/color]

                      You don't call a struct. It's just a bunch of data.
                      [color=blue]
                      > Is data all they hold?[/color]

                      Yes. That data can, in fact, include pointers to functions, but they're just
                      data too.
                      [color=blue]
                      > This and pointers are the major sticking points for me with C.[/color]

                      Get a better C book, then.
                      [color=blue]
                      > And when
                      > there are bunches of parenthesis such as (((((*c))))))). That's confusing.[/color]

                      This reduces to *c)) which (on its own) is a syntax error. Don't be confused
                      by syntax errors. Just fix them.

                      --
                      Richard Heathfield : binary@eton.pow ernet.co.uk
                      "Usenet is a strange place." - Dennis M Ritchie, 29 July 1999.
                      C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
                      K&R answers, C books, etc: http://users.powernet.co.uk/eton

                      Comment

                      • Richard Heathfield

                        #26
                        Re: Source

                        Mark A. Odell wrote:
                        [color=blue][color=green][color=darkred]
                        >>> struct GUID guid;
                        >>> memset(guid, 0, sizeof guid);[/color]
                        >>
                        >> This isn't a very good idea.[/color]
                        >
                        > Are you concerned about traps? I suppose this may not be fully portable
                        > but I admit I am guilty of doing this quite often.[/color]

                        That's certainly an issue if the struct contains non-integer types, but I'm
                        more worried about compiler diagnostics. Look at your first argument to
                        memset again, more closely. Then look up the definition of memset.

                        --
                        Richard Heathfield : binary@eton.pow ernet.co.uk
                        "Usenet is a strange place." - Dennis M Ritchie, 29 July 1999.
                        C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
                        K&R answers, C books, etc: http://users.powernet.co.uk/eton

                        Comment

                        • Mark Gordon

                          #27
                          Re: Source

                          On Thu, 09 Oct 2003 21:15:32 GMT
                          Matt Gregory <bleah-no-more-spam@earthlink. net> wrote:
                          [color=blue]
                          > Mark A. Odell wrote:
                          >[color=green]
                          > > Sheldon Simms <sheldonsimms@y ahoo.com> wrote in
                          > > news:pan.2003.1 0.09.20.13.51.7 85991@yahoo.com :
                          > >[color=darkred]
                          > >>>struct GUID guid;
                          > >>>memset(gui d, 0, sizeof guid);
                          > >>
                          > >>This isn't a very good idea.[/color]
                          > >
                          > >
                          > > Are you concerned about traps? I suppose this may not be fully
                          > > portable but I admit I am guilty of doing this quite often.[/color]
                          >
                          > What's wrong with it?[/color]

                          It sets all bits zero. Unfortunately all bits set to zero could be a
                          trap representation for some of the elements of struct GUID depending
                          on that type they are.
                          --
                          Mark Gordon
                          Paid to be a Geek & a Senior Software Developer
                          Although my email address says spamtrap, it is real and I read it.

                          Comment

                          • Dan Pop

                            #28
                            Re: Source

                            In <Xns940FAAE74BF 66CopyrightMark Odell@130.133.1 .4> "Mark A. Odell" <nospam@embedde dfw.com> writes:
                            [color=blue]
                            >Sheldon Simms <sheldonsimms@y ahoo.com> wrote in
                            >news:pan.2003. 10.09.20.13.51. 785991@yahoo.co m:
                            >[color=green][color=darkred]
                            >>> But if I actually wanted a GUID object, and not a pointer to one,
                            >>> initialzed to zero I'd need to write:
                            >>>
                            >>> struct GUID guid = { 0 };[/color]
                            >>
                            >> Ok.
                            >>[color=darkred]
                            >>> or
                            >>>
                            >>> struct GUID guid;
                            >>> memset(guid, 0, sizeof guid);[/color]
                            >>
                            >> This isn't a very good idea.[/color]
                            >
                            >Are you concerned about traps? I suppose this may not be fully portable
                            >but I admit I am guilty of doing this quite often.[/color]

                            Not necessarily traps, but non-integer structure members may not be
                            initialised to zero or null pointers. Of course, this is an issue only
                            when portability to weird platforms is a valid concern (neither null
                            pointers nor floating point zero need be represented as all bits zero).

                            Dan
                            --
                            Dan Pop
                            DESY Zeuthen, RZ group
                            Email: Dan.Pop@ifh.de

                            Comment

                            • Mark A. Odell

                              #29
                              Re: Source

                              Richard Heathfield <dontmail@addre ss.co.uk.invali d> wrote in
                              news:bm5l54$j72 $2@hercules.bti nternet.com:
                              [color=blue][color=green][color=darkred]
                              >>>> struct GUID guid;
                              >>>> memset(guid, 0, sizeof guid);
                              >>>
                              >>> This isn't a very good idea.[/color]
                              >>
                              >> Are you concerned about traps? I suppose this may not be fully portable
                              >> but I admit I am guilty of doing this quite often.[/color]
                              >
                              > That's certainly an issue if the struct contains non-integer types, but
                              > I'm more worried about compiler diagnostics. Look at your first argument
                              > to memset again, more closely. Then look up the definition of memset.[/color]

                              Yikes!

                              memset(&guid, 0, sizeof guid);

                              I will, from this point forth, no longer use memset() on structs even if I
                              know it contains no data types that can have trap values.

                              --
                              - Mark ->
                              --

                              Comment

                              • Bill Cunningham

                                #30
                                Re: Source

                                So the character after the last } of a struct and before ; is for a typedef?
                                What about this.

                                struct A{
                                int a;
                                *_point;}Ab; /* is the Ab an alias? */

                                Bill





                                -----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
                                http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
                                -----== Over 100,000 Newsgroups - 19 Different Servers! =-----

                                Comment

                                Working...