Groups | Search | Server Info | Login | Register


Groups > comp.os.os2.programmer.porting > #111

Re: VirtualAlloc to DosAllocMem

From "Lars Erdmann" <lars.erdmann@arcor.de>
Newsgroups comp.os.os2.programmer.porting
References <iv5rr7$dqt$1@speranza.aioe.org> <4e176267$0$6545$9b4e6d93@newsspool4.arcor-online.net> <slrnj1f34j.3nn.abuse@news.pr.network>
Subject Re: VirtualAlloc to DosAllocMem
Date 2011-07-09 03:46 +0200
Message-ID <4e17b2e3$0$6555$9b4e6d93@newsspool4.arcor-online.net> (permalink)
Organization Arcor

Show all headers | View raw


"Paul Ratcliffe" <abuse@orac12.clara34.co56.uk78> schrieb im Newsbeitrag 
news:slrnj1f34j.3nn.abuse@news.pr.network...
> On Fri, 08 Jul 2011 22:03:12 +0200, Heiko Nitzsche
> <hn-expires-27nov11@arcor.de> wrote:
>
>> Well, I'd propose the following:
>>
>> static inline DWORD protection(bool writable, bool executable)
>> {
>>    return executable ?
>>           (writable ? (PAG_EXECUTE | PAG_READ | PAG_WRITE) : (PAG_EXECUTE 
>> | PAG_READ) :
>>           (writable ? (              PAG_READ | PAG_WRITE) : 
>> PAG_READ);
>> }
>>
>> You could also write it this way:
>>
>> static inline DWORD protection(bool writable, bool executable)
>> {
>>    DWORD permissions = PAG_READ; // always readable
>>    if (writable)
>>    {
>>      permissions |= PAG_WRITE; // allow writing
>>    }
>>    if (executable)
>>    {
>>      permissions |= PAG_EXECUTE; // content may be executed
>>    }
>>    return permissions;
>> }
>
> Strewth, you like typing don't you...
>
> return PAG_READ | (writable ? PAG_WRITE : 0) | (executable ? PAG_EXECUTE : 
> 0);
>
> ... but why use 1 line when you can use 10, eh?

It's all a matter of style. In the end, most compilers will generate the 
same binary code from that.
At least if the optimizer is turned on. It depends on what you consider to 
be better readable.

By the way: In a DO178B project people might rip your balls off if they see 
"condensed" code like you have been writing.

Lars

Back to comp.os.os2.programmer.porting | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

VirtualAlloc to DosAllocMem Dave Yeo <dave.r.yeo@gmail.com> - 2011-07-07 19:59 -0700
  Re: VirtualAlloc to DosAllocMem Heiko Nitzsche <hn-expires-27nov11@arcor.de> - 2011-07-08 22:03 +0200
    Re: VirtualAlloc to DosAllocMem Heiko Nitzsche <hn-expires-27nov11@arcor.de> - 2011-07-08 22:14 +0200
      Re: VirtualAlloc to DosAllocMem Dave Yeo <dave.r.yeo@gmail.com> - 2011-07-08 19:39 -0700
        Re: VirtualAlloc to DosAllocMem Dave Yeo <dave.r.yeo@gmail.com> - 2011-07-08 21:57 -0700
    Re: VirtualAlloc to DosAllocMem Paul Ratcliffe <abuse@orac12.clara34.co56.uk78> - 2011-07-08 23:02 +0000
      Re: VirtualAlloc to DosAllocMem "Lars Erdmann" <lars.erdmann@arcor.de> - 2011-07-09 03:46 +0200
        Re: VirtualAlloc to DosAllocMem Paul Ratcliffe <abuse@orac12.clara34.co56.uk78> - 2011-07-09 11:32 +0000
          Re: VirtualAlloc to DosAllocMem Paul Smedley <paulDESPAM@DESPAMMsmedley.id.au> - 2011-07-10 11:39 +0930

csiph-web