Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #43676

Re: Defined and undefined C pointer manipulation

From Keith Thompson <kst-u@mib.org>
Newsgroups comp.lang.c
Subject Re: Defined and undefined C pointer manipulation
Date 2014-04-27 13:01 -0700
Organization None to speak of
Message-ID <lnvbtupmnt.fsf@nuthaus.mib.org> (permalink)
References <ljgqns$t1i$1@dont-email.me> <pointers-20140426195429@ram.dialup.fu-berlin.de> <ljjhvo$9o6$1@dont-email.me>

Show all headers | View raw


"James Harris" <james.harris.1@gmail.com> writes:
> "Stefan Ram" <ram@zedat.fu-berlin.de> wrote in message 
> news:pointers-20140426195429@ram.dialup.fu-berlin.de...
>> "James Harris" <james.harris.1@gmail.com> writes:
>>>ptr |= 1;
>>
>>      »Each of the operands shall have integer type.«
>>
>>    6.5.12 Bitwise inclusive OR operator, N1570
>
> That's an interesting point. Since C allows (or at least implementations of 
> C allow) such operations on a pointer and, as you point out, the operands 
> are required by the standard to be of integer type does that imply that the 
> pointer gets 'converted' to an integer for the bitwise operation to take 
> place? In other words, does the compiler perform an implementation specific 
> conversion to an integer so that the bitwise OR can be done? And if it does 
> wouldn't it 'convert' it to a [u]intptr_t? Maybe it's going too far to say 
> that would be safe.

No, it means that any code that attempts to apply the bitwise OR
operator "|" to a pointer value violates a constraint.  A conforming
compiler must diagnose it and may reject it.  (A decent compiler, IMHO,
will reject it.)

If you want to perform bitwise operations on pointer representations,
you simply have to convert them yourself.

[...]

> I know what you mean - when programming in C we nearly always use malloc for 
> memory allocation - though it could be argued that malloc is not a C 
> function. AIUI malloc is not part of C at all but merely part of the 
> standard library, and that some other allocator could be used just as well 
> and the program which still be wholly C.

The malloc() function is part of the C standard library.  Section 6 of
the C standard describes the language; section 7 defines the library.
malloc() is as much a part of standard C as "int" and "+" (except that,
like most of the library, it's optional for freestanding
implementations).

malloc() needn't be *implemented* in C, but I don't think that's the
point you were making.

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
Working, but not speaking, for JetHead Development, Inc.
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"

Back to comp.lang.c | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Defined and undefined C pointer manipulation "James Harris" <james.harris.1@gmail.com> - 2014-04-26 18:35 +0100
  Re: Defined and undefined C pointer manipulation Keith Thompson <kst-u@mib.org> - 2014-04-26 12:04 -0700
    Re: Defined and undefined C pointer manipulation "James Harris" <james.harris.1@gmail.com> - 2014-04-27 19:11 +0100
      Re: Defined and undefined C pointer manipulation Barry Schwarz <schwarzb@dqel.com> - 2014-04-27 11:46 -0700
        Re: Defined and undefined C pointer manipulation Keith Thompson <kst-u@mib.org> - 2014-04-27 12:46 -0700
        Re: Defined and undefined C pointer manipulation Ben Bacarisse <ben.usenet@bsb.me.uk> - 2014-04-28 02:53 +0100
      Re: Defined and undefined C pointer manipulation Keith Thompson <kst-u@mib.org> - 2014-04-27 12:57 -0700
        Re: Defined and undefined C pointer manipulation "James Harris" <james.harris.1@gmail.com> - 2014-04-27 21:56 +0100
          Re: Defined and undefined C pointer manipulation Keith Thompson <kst-u@mib.org> - 2014-04-27 14:25 -0700
            Re: Defined and undefined C pointer manipulation glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2014-04-27 22:51 +0000
  Re: Defined and undefined C pointer manipulation Malcolm McLean <malcolm.mclean5@btinternet.com> - 2014-04-27 06:21 -0700
    Re: Defined and undefined C pointer manipulation "BartC" <bc@freeuk.com> - 2014-04-27 16:51 +0100
      Re: Defined and undefined C pointer manipulation Malcolm McLean <malcolm.mclean5@btinternet.com> - 2014-04-27 10:36 -0700
      Re: Defined and undefined C pointer manipulation Ian Collins <ian-news@hotmail.com> - 2014-04-28 11:40 +1200
  Re: Defined and undefined C pointer manipulation "James Harris" <james.harris.1@gmail.com> - 2014-04-27 19:23 +0100
    Re: Defined and undefined C pointer manipulation Richard Damon <Richard@Damon-Family.org> - 2014-04-27 14:56 -0400
      Re: Defined and undefined C pointer manipulation "James Harris" <james.harris.1@gmail.com> - 2014-04-27 20:52 +0100
        Re: Defined and undefined C pointer manipulation Keith Thompson <kst-u@mib.org> - 2014-04-27 13:16 -0700
    Re: Defined and undefined C pointer manipulation "BartC" <bc@freeuk.com> - 2014-04-27 20:55 +0100
      Re: Defined and undefined C pointer manipulation "James Harris" <james.harris.1@gmail.com> - 2014-04-27 21:20 +0100
        Re: Defined and undefined C pointer manipulation glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2014-04-27 22:39 +0000
        Re: Defined and undefined C pointer manipulation glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2014-04-27 22:43 +0000
        Re: Defined and undefined C pointer manipulation "BartC" <bc@freeuk.com> - 2014-04-28 00:13 +0100
    Re: Defined and undefined C pointer manipulation Keith Thompson <kst-u@mib.org> - 2014-04-27 13:01 -0700
    Re: Defined and undefined C pointer manipulation James Kuyper <jameskuyper@verizon.net> - 2014-04-27 22:07 -0400
    Re: Defined and undefined C pointer manipulation Malcolm McLean <malcolm.mclean5@btinternet.com> - 2014-04-28 00:47 -0700
      Re: Defined and undefined C pointer manipulation Ian Collins <ian-news@hotmail.com> - 2014-04-28 20:01 +1200
        Re: Defined and undefined C pointer manipulation Malcolm McLean <malcolm.mclean5@btinternet.com> - 2014-04-28 02:11 -0700
          Re: Defined and undefined C pointer manipulation Ian Collins <ian-news@hotmail.com> - 2014-04-28 22:38 +1200
            Re: Defined and undefined C pointer manipulation Malcolm McLean <malcolm.mclean5@btinternet.com> - 2014-04-28 04:50 -0700
      Re: Defined and undefined C pointer manipulation "BartC" <bc@freeuk.com> - 2014-04-28 09:22 +0100
        Re: Defined and undefined C pointer manipulation Malcolm McLean <malcolm.mclean5@btinternet.com> - 2014-04-28 05:31 -0700

csiph-web