Path: csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: C Programming Tutorial on Youtube Date: Sat, 15 Oct 2016 16:19:45 -0700 Organization: None to speak of Lines: 75 Message-ID: References: <8be0cdbe-c2f4-42ec-b6a7-e9a154981718@googlegroups.com> <878ttp5vph.fsf@bsb.me.uk> <87twcd47s4.fsf@bsb.me.uk> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="47375d5ce36f0082b94983afe63eb3b3"; logging-data="2955"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19c+uusSvsmcf9T2GXT7l48" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:eVtrpR27ZZ9S2e1byeDsRJcNTec= sha1:HQ3ukPBsvWNKoX1WKVU8TJWR2Yo= Xref: csiph.com comp.lang.c:94891 BartC writes: > On 15/10/2016 22:33, Ben Bacarisse wrote: >> BartC writes: >>> You understand that in RD's example, and disregarding type, there is >>> an extra level of indirection between the value of 'pointer' and the >>> value of &buffer? >> >> No, I don't understand that. What do you mean by it? > > I didn't realise my language was up to it, but it can define true > constant pointers (to fixed addresses anyway): > > const ref byte p = ref byte(0xC000) # NOT C > byte a > > a = p^ > > This generates this C: > > a = *49152; That's a constraint violation. Is your intent to translate your language to valid C? > While a non-constant pointer would result in: > > char * p = 49152; > > a = *p; > > It shows that C can have constant pointers, but like named integer > literals, it has the same issues with named constant pointers (or > pointer literals, although such pointers would normally refer to some > symbol not a hardcoded address). > > Of course C can struggle through and there are any number of ways of > achieving a constant pointer without the indirection: > > #define p 0xC000 The value of p is an integer, not a pointer. > enum {p = 0xC000}; // this might work, if value is in range Again, that's an integer. > char * const p = 0xC000 // hope the compiler will optimise it And a constraint violation. Perhaps what you're looking for is char *const p = (const char*)0xC000; but p still isn't a constant expression. > *p; > > but they're all beating around the bush because the language simply > doesn't allow you to express exactly what you mean in a way in a > completely general way. C does have expressions that are *address constants* (N1570 6.6p9). It doesn't have a good way of naming them; an identifier (other than a macro name or an enumerator with the value 0) cannot be an address constant, even if it's the name of a const object initialized to an address constant. [...] -- Keith Thompson (The_Other_Keith) kst-u@mib.org 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"