Sign in

username:

password:



Not a member?

Search Comp.Arch.Embedded



Search tips

embedded by Keywords

68HC11 | 68HC12 | 8051 | 8052 | ARM | ARM7 | Asic | AT91 | AT91RM9200 | Atmel | AVR | AVRStudio | Bootloader | CFP | CompactFlash | Cygnal | Cypress | Dataflash | DSP | eCos | EEPROM | Embedded Linux | Emulator | Endian | Ethernet | Firewire | FPGA | Freescale | GCC | GNUARM | GSM | H8 | HDLC | I2C | Infineon | Interrupts | Java | JTAG | LCD | LED | LPC2000 | MCU | Microchip | MMC | MPLAB | MSP430 | PC104 | PCB | PCI | PCMCIA | PowerPC | Rabbit | RS232 | RS485 | RTOS | SBC | SDRAM | Sensor | SPI | STK500 | UART | UML | USART | USB | Verilog | VHDL | VxWorks | Xilinx

Discussion Groups

Discussion Groups | Comp.Arch.Embedded | My idea of fully-portable C code

There are 53 messages in this thread.

You are currently looking at messages 50 to 53.

Re: My idea of fully-portable C code - =?windows-1252?Q?W4tch3r_=8B=95=BF=95=9B?= - 02:38 15-05-08



CBFalconer wrote:
> I trust you meant 243.  You can also quickly multiply by 3 on very
> simple hardware, by shift and add twice.

yes thanks! 243
W4tch3r ‹•¿•›

Re: My idea of fully-portable C code - Thad Smith - 23:45 15-05-08

Chris H wrote:
> In message 
> <b...@26g2000hsk.googlegroups.com>, 
> Tomás Ó hÉilidhe <t...@lavabit.com> writes
>> On May 13, 7:59 pm, Hans-Bernhard Bröker <HBBroe...@t-online.de>
>> wrote:
>>> > #define TOTAL_BITS_NEEDED (QUANTITY_CHUNKS * BITS_PER_CHUNK)
>>>
>>> Bad macro.  Parentheses missing around QUANTITY_CHUNKS and
>>> BITS_PER_CHUNK leave the code vulnerable to funny definitions of those
>>> constants (e.g. #define BITS_PER_CHUNK 2+3)  The same problem occurs
>>> repeatedly later on.
>>
>> You're confusing things. A macro is a self-contained, self-sufficient
>> entity. If I have a macro called QUANTITY_CHUNKS, then it should be
>> able to be used on its own without parentheses. If it needs
>> parentheses, then it is ill-formed.
> 
> Now you are running counter to most standards and guides for portability 
> and safety.

I suspect Chris misunderstands Tomas's point: that macros defining numeric 
expressions should have surrounding parentheses in the macro definition so 
they aren't required where they are used.  So

#define FOO (BAR+3)
  x = FOO+4;

rather than

#define FOO BAR+3
  x = (FOO)*4;

Hans-Bernard's point, of being paranoid of externally-defined macros and 
surrounding those with parentheses is good, of course.

-- 
Thad

Re: My idea of fully-portable C code - Eric Smith - 20:28 21-05-08

CBFalconer wrote:
> You can also quickly multiply by 3 on very
> simple hardware, by shift and add twice.

Can't you multiply by three by shifting and adding *once*?

previous | 1 | 2 | 3 | 4 | 5 | 6