out

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Bill Cunningham

    out

    #include <stdio.h>

    int out(int n, char *buffer) {
    if (n=(int)NULL) {
    return puts(buffer);
    }
    if (n=1) {
    return fputs(buffer,st dout);
    }
    if(n!=1||n!=(in t)NULL) {
    fprintf(stderr, "Usage error\n");
    return 0;
    }
    }

    The above code before I added the int casts just by a gut feeling didn't
    work. By adding the int casts in front of the NULLs what have I really done?
    I hope the wrote the right thing. The code before the int casts compiled
    into an object file but the compiler through bash's stderr gave me warnings
    that I needed casts. Have I corrected a portability problem. It's not good
    to guess things even if it's right but to know what you did.

    Bill


  • Default User

    #2
    Re: out

    vippstar@gmail. com wrote:
    On Apr 6, 2:19 am, Ian Collins <ian-n...@hotmail.co mwrote:
    Is this a troll?
    >
    As I said before, this Bill Cunningham person is a troll.
    Yet a lot of people ignore me and continue to respond...
    Either a troll or completely unable to learn the language. It's a
    complete waste of time to attempt a dialog.



    Brian

    Comment

    • Ian Collins

      #3
      Re: out

      Bill Cunningham wrote:
      >
      I didn't know if 0 was portable or not.
      >
      0, not portable? How about 1 or 2?

      --
      Ian Collins.

      Comment

      • Default User

        #4
        Re: out

        Keith Thompson wrote:

        We don't ignore you, we merely disagree. I don't believe he's a
        deliberate troll. He's said he has some sort of learning disability
        but is trying to learn C in spite of it. I've seen no reason to
        disbelieve him.
        He's supposedly been learning C since 2002 or so, and has made no more
        progress than this. If he's not a troll, then everyone needs to realize
        that it ain't gonna happen.




        Brian

        Comment

        • Harald van =?UTF-8?b?RMSzaw==?=

          #5
          Re: out

          On Mon, 07 Apr 2008 07:15:48 +0200, Richard wrote:
          What does a NULL pointer show up as when stored as a value in a sizeof
          (ptr) block of bytes? How does this differentiate from all other valid
          memory pointers (especially ones pointing to address 0)?
          On one implementation I have access to, a null pointer is stored as
          0x55555555, while a pointer to address zero is stored as 0x00000000.

          Comment

          • Richard

            #6
            Re: out

            Harald van Dijk <truedfx@gmail. comwrites:
            On Mon, 07 Apr 2008 07:15:48 +0200, Richard wrote:
            >What does a NULL pointer show up as when stored as a value in a sizeof
            >(ptr) block of bytes? How does this differentiate from all other valid
            >memory pointers (especially ones pointing to address 0)?
            >
            On one implementation I have access to, a null pointer is stored as
            0x55555555, while a pointer to address zero is stored as 0x00000000.
            And the maximum address of the memory space is?

            Does "if(!p)" work when p is your NULL?

            Comment

            • Harald van =?UTF-8?b?RMSzaw==?=

              #7
              Re: out

              On Mon, 07 Apr 2008 19:15:49 +0200, Richard wrote:
              Harald van Dijk <truedfx@gmail. comwrites:
              >On Mon, 07 Apr 2008 07:15:48 +0200, Richard wrote:
              >>What does a NULL pointer show up as when stored as a value in a sizeof
              >>(ptr) block of bytes? How does this differentiate from all other valid
              >>memory pointers (especially ones pointing to address 0)?
              >>
              >On one implementation I have access to, a null pointer is stored as
              >0x55555555, while a pointer to address zero is stored as 0x00000000.
              >
              And the maximum address of the memory space is?
              0xFFFFFFFF. There's no special reason why 0x55555555 would not be
              addressable, just as there's no special reason why 0x00000000 would not
              be addressable.
              Does "if(!p)" work when p is your NULL?
              Yes. p behaves as true when it points to address 0, and as false when it
              is a null pointer / points to address 0x55555555.

              Comment

              • Richard

                #8
                Re: out

                Harald van Dijk <truedfx@gmail. comwrites:
                On Mon, 07 Apr 2008 19:15:49 +0200, Richard wrote:
                >Harald van Dijk <truedfx@gmail. comwrites:
                >>On Mon, 07 Apr 2008 07:15:48 +0200, Richard wrote:
                >>>What does a NULL pointer show up as when stored as a value in a sizeof
                >>>(ptr) block of bytes? How does this differentiate from all other valid
                >>>memory pointers (especially ones pointing to address 0)?
                >>>
                >>On one implementation I have access to, a null pointer is stored as
                >>0x55555555, while a pointer to address zero is stored as 0x00000000.
                >>
                >And the maximum address of the memory space is?
                >
                0xFFFFFFFF. There's no special reason why 0x55555555 would not be
                addressable, just as there's no special reason why 0x00000000 would not
                be addressable.
                So what is the address pointer pointing to address 0x55555555 stored as
                when stored in memory?
                >Does "if(!p)" work when p is your NULL?
                >
                Yes. p behaves as true when it points to address 0, and as false when it
                is a null pointer / points to address 0x55555555.

                Comment

                • Harald van =?UTF-8?b?RMSzaw==?=

                  #9
                  Re: out

                  On Mon, 07 Apr 2008 19:47:54 +0200, Richard wrote:
                  Harald van Dijk <truedfx@gmail. comwrites:
                  >On Mon, 07 Apr 2008 19:15:49 +0200, Richard wrote:
                  >>Harald van Dijk <truedfx@gmail. comwrites:
                  >>>On Mon, 07 Apr 2008 07:15:48 +0200, Richard wrote:
                  >>>>What does a NULL pointer show up as when stored as a value in a
                  >>>>sizeof (ptr) block of bytes? How does this differentiate from all
                  >>>>other valid memory pointers (especially ones pointing to address 0)?
                  >>>>
                  >>>On one implementation I have access to, a null pointer is stored as
                  >>>0x55555555 , while a pointer to address zero is stored as 0x00000000.
                  >>>
                  >>And the maximum address of the memory space is?
                  >>
                  >0xFFFFFFFF. There's no special reason why 0x55555555 would not be
                  >addressable, just as there's no special reason why 0x00000000 would not
                  >be addressable.
                  >
                  So what is the address pointer pointing to address 0x55555555 stored as
                  when stored in memory?
                  As 0x55555555. What is a pointer to address 0x00000000 stored as on your
                  system?

                  Comment

                  • Kenny McCormack

                    #10
                    Re: out

                    In article <ftdks7$lhr$1@r egistered.motza rella.org>,
                    Richard <devr_@gmail.co mwrote:
                    >Harald van Dijk <truedfx@gmail. comwrites:
                    >
                    >On Mon, 07 Apr 2008 07:15:48 +0200, Richard wrote:
                    >>What does a NULL pointer show up as when stored as a value in a sizeof
                    >>(ptr) block of bytes? How does this differentiate from all other valid
                    >>memory pointers (especially ones pointing to address 0)?
                    >>
                    >On one implementation I have access to, a null pointer is stored as
                    >0x55555555, while a pointer to address zero is stored as 0x00000000.
                    >
                    >And the maximum address of the memory space is?
                    >
                    >Does "if(!p)" work when p is your NULL?
                    >
                    One suspects that Harald is, er, what's the word I'm looking for, oh,
                    yeah, here it is, lying.

                    It is a frequent tactic of the regs to speak, for pedagogic purposes, as
                    if the DS9000 actually exists and, further, that they use one on a
                    regular basis.

                    Many would have us believe that they have one in their basement.

                    Comment

                    • Harald van =?UTF-8?b?RMSzaw==?=

                      #11
                      Re: out

                      On Mon, 07 Apr 2008 18:01:59 +0000, Kenny McCormack wrote:
                      >>Harald van Dijk <truedfx@gmail. comwrites:
                      >>On one implementation I have access to, a null pointer is stored as
                      >>0x55555555, while a pointer to address zero is stored as 0x00000000.
                      >
                      One suspects that Harald is, er, what's the word I'm looking for, oh,
                      yeah, here it is, lying.
                      >
                      It is a frequent tactic of the regs to speak, for pedagogic purposes, as
                      if the DS9000 actually exists and, further, that they use one on a
                      regular basis.
                      It's hardly a DS9000. If you're interested in details, you could just
                      ask. If you're not interested in details, that's fine too, then just
                      continue as you're doing now, I won't get in your way.
                      Many would have us believe that they have one in their basement.

                      Comment

                      • Harald van =?UTF-8?b?RMSzaw==?=

                        #12
                        Re: out

                        On Mon, 07 Apr 2008 20:36:14 +0100, Flash Gordon wrote:
                        Granted. Now what system is it that uses 0x55555555 as the
                        representation of a null pointer?
                        The x86 translator (backend) of tendra has an option to use 0x55555555 as
                        the representation of a null pointer. It's usable on Linux or the BSD
                        variants and capable of acting as a hosted implementation if you compile
                        libc with this option, or a freestanding implementation if you don't. To
                        be honest, I suspect it was only added as a test to make sure they would
                        be able to port to a system where null pointers with set bits were
                        already used, but whatever the reason, there it is.

                        Comment

                        • Keith Thompson

                          #13
                          Re: out

                          Harald van Dijk <truedfx@gmail. comwrites:
                          On Mon, 07 Apr 2008 07:15:48 +0200, Richard wrote:
                          >What does a NULL pointer show up as when stored as a value in a sizeof
                          >(ptr) block of bytes? How does this differentiate from all other valid
                          >memory pointers (especially ones pointing to address 0)?
                          >
                          On one implementation I have access to, a null pointer is stored as
                          0x55555555, while a pointer to address zero is stored as 0x00000000.
                          Fascinating.

                          What system is it? Does it have a conforming C implementation (or
                          even a non-conforming C-like implementation) ?

                          --
                          Keith Thompson (The_Other_Keit h) <kst-u@mib.org>
                          Nokia
                          "We must do something. This is something. Therefore, we must do this."
                          -- Antony Jay and Jonathan Lynn, "Yes Minister"

                          Comment

                          • Keith Thompson

                            #14
                            Re: out

                            Richard <devr_@gmail.co mwrites:
                            [...]
                            Note : I'm not trolling here. I'm just trying to find the "perfect
                            explanation" for the benefit of others. In too many places there is zero
                            or null (:-)) understanding of NULL not being the same as a zero
                            pointer.
                            [...]

                            The best explanation I've seen is section 5 of the comp.lang.c FAQ,
                            <http://www.c-faq.com/>.

                            --
                            Keith Thompson (The_Other_Keit h) <kst-u@mib.org>
                            Nokia
                            "We must do something. This is something. Therefore, we must do this."
                            -- Antony Jay and Jonathan Lynn, "Yes Minister"

                            Comment

                            • Harald van =?UTF-8?b?RMSzaw==?=

                              #15
                              Re: out

                              On Mon, 07 Apr 2008 13:23:19 -0700, Keith Thompson wrote:
                              Harald van Dijk <truedfx@gmail. comwrites:
                              >On Mon, 07 Apr 2008 07:15:48 +0200, Richard wrote:
                              >>What does a NULL pointer show up as when stored as a value in a sizeof
                              >>(ptr) block of bytes? How does this differentiate from all other valid
                              >>memory pointers (especially ones pointing to address 0)?
                              >>
                              >On one implementation I have access to, a null pointer is stored as
                              >0x55555555, while a pointer to address zero is stored as 0x00000000.
                              >
                              Fascinating.
                              >
                              What system is it? Does it have a conforming C implementation (or even
                              a non-conforming C-like implementation) ?
                              The hardware is the same x86 anyone can easily get. It's purely the
                              compiler that can be configured to give null pointers the representation
                              0x55555555. The compiler is tendra, it runs on Linux or the various BSD
                              flavours (or perhaps other systems, but those I know of), and to the best
                              of my knowledge, it conforms to C90.

                              Comment

                              Working...