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

Ads

Discussion Groups

Discussion Groups | Comp.Arch.Embedded | Interview Embedded Software Questions

There are 127 messages in this thread.

You are currently looking at messages 90 to 100.

Re: Interview Embedded Software Questions - Yuriy K. - 13:32 16-11-06

Vladimir Vassilevsky wrote:
>>> Ask to write code to toggle a variable from 0->1->0...
>> Which is a correct and proper way to do this.
>> if (a) a = 0;
>> else   a = 1;
> 
> No, it is not.
> 
> if(a != 0)
>  {
>  a = 0;
>  }
> else
>  {
>  a = 1;
>  }


> MISRA Rulez.

MISRA is good, but sometimes way too restrictive for my taste.


> Alternative acceptable realization:
> 
> template <class T> toggle(T& a);

Better. Since it may be plain C, simple
a = toggle_0_1(a);
would do. :)


>>> Or ask them how to test a bit in a peripheral register.
>>
>>
>> (tst_bit(register, 3)
> 
> Dirty hack.
> There is no such things as bits and registers.

On the application level, of course not, but that was not the question.

> if(something_happened())
>  {
>  }

Well, someone has to implement "something_happened()" function. :)

-- 
WBR, Yuriy.
"Resistance is futile"



Re: Interview Embedded Software Questions - CBFalconer - 14:02 16-11-06

"Yuriy K." wrote:
> Rainer Buchty wrote:
> 
... snip ...
> 
>> So if the *programmer* knows that "a" is either 0 or 1, why
>> shouldn't he write "a^=1;" (or "a^=SOME_MASK;" for the arbitrary
>> case) right from the beginning but rather if/then?
> 
> Because three years later new programmer will spend two hours
> trying to figure out if *a* can or can not be equal to 2 or 3, and
> what is this silly line meant to do.

Which is handled concisely by the (elsethread) suggestion:

   a = !a;

Other possibilities include using the C99 declaration

   #include <stdbool.h>

   bool a;

or using Pascal

   a : boolean;

-- 
Chuck F (cbfalconer at maineline dot net)
   Available for consulting/temporary embedded and systems.
   <http://cbfalconer.home.att.net>;


Re: Interview Embedded Software Questions - Darin Johnson - 15:08 16-11-06

Arlet wrote:
> If it doesn't need to be optimized, I prefer this version:
>
>     a = !a;

That has the advantage of still working even if "a = 2".

--
Darin Johnson


Re: Interview Embedded Software Questions - Ulf Samuelsson - 17:01 16-11-06

>> Any other ideas for interview questions?
>
>
> Ask to write code to toggle a variable from 0->1->0...
>
> We often saw this:
>
> if ( a == 0 ){ a=1;} else {a = 0;}
>
> instead of e.g
> a = 1-a; or a^= 1;
>

    VAR flag: Boolean;

    flag = not flag;

    or did you have to write in C ;-)

-- 
Best Regards,
Ulf Samuelsson
u...@a-t-m-e-l.com
This message is intended to be my own personal view and it
may or may not be shared by my employer Atmel Nordic AB 



Re: Interview Embedded Software Questions - Jim Granville - 18:58 16-11-06

Ulf Samuelsson wrote:

>>>Any other ideas for interview questions?
>>
>>
>>Ask to write code to toggle a variable from 0->1->0...
>>
>>We often saw this:
>>
>>if ( a == 0 ){ a=1;} else {a = 0;}
>>
>>instead of e.g
>>a = 1-a; or a^= 1;
>>
> 
> 
>     VAR flag: Boolean;
> 
>     flag = not flag;
> 
>     or did you have to write in C ;-)

Of course not.

and equally valid answers to the question are

TX	BIT	P0.4
	CPL	TX

or

PIN = Flag;
Flag.d = !Flag;   /* toggles on every CLK */

-jg



Re: Interview Embedded Software Questions - CBFalconer - 19:33 16-11-06

Ulf Samuelsson wrote:
> 
>>> Any other ideas for interview questions?
>>
>> Ask to write code to toggle a variable from 0->1->0...
>>
>> We often saw this:
>>
>> if ( a == 0 ){ a=1;} else {a = 0;}
>>
>> instead of e.g
>> a = 1-a; or a^= 1;
> 
>     VAR flag: Boolean;
> 
>     flag = not flag;

           :=    :-)
> 
> or did you have to write in C ;-)

-- 
Chuck F (cbfalconer at maineline dot net)
   Available for consulting/temporary embedded and systems.
   <http://cbfalconer.home.att.net>;



Re: Interview Embedded Software Questions - Jim Granville - 21:03 16-11-06

CBFalconer wrote:

> Ulf Samuelsson wrote:
> 
>>>>Any other ideas for interview questions?
>>>
>>>Ask to write code to toggle a variable from 0->1->0...
>>>
>>>We often saw this:
>>>
>>>if ( a == 0 ){ a=1;} else {a = 0;}
>>>
>>>instead of e.g
>>>a = 1-a; or a^= 1;
>>
>>    VAR flag: Boolean;
>>
>>    flag = not flag;
> 
> 
>            :=    :-)

Does that mean Ulf would have failed the interview ? :)

The questioner could have required this line :
[Will compile in both Pascal and Modula-2 ]

  flag := NOT flag;

-jg


Re: Interview Embedded Software Questions - 42Bastian Schick - 01:34 17-11-06

On Thu, 16 Nov 2006 12:22:55 -0600, "Yuriy K." <y...@mail.ru> wrote:


>> Next question: Compute the square root of an integer.
>> Yuriy's answer: s = squareroot(a);
>
>Actually, it is
>s = sqrt(a);
>C programmer shall know basic standard library functions.

Sorry, failed. Question was: "...squart root of an integer"
Your solution imposes two castings and pulls in floating point
arithmetics.


-- 
42Bastian
Do not email to b...@yahoo.com, it's a spam-only account :-)
Use <same-name>@monlynx.de instead !

Re: Interview Embedded Software Questions - 42Bastian Schick - 01:38 17-11-06

On Thu, 16 Nov 2006 12:28:56 -0600, "Yuriy K." <y...@mail.ru> wrote:

>
>Because three years later new programmer will spend two hours trying to 
>figure out if *a* can or can not be equal to 2 or 3, and what is this 
>silly line meant to do.

I expect a "new programmer" to understand the whole source he is
responsible for and not only one line of code.

Most code (C,Assembler, Cobol ....) is hard to understand without
the context.

>
>More often than not it is more important than saving two bytes and 500 
>nanoseconds.

It is about embedded where 500ns could mean "go" or "no go".

-- 
42Bastian
Do not email to b...@yahoo.com, it's a spam-only account :-)
Use <same-name>@monlynx.de instead !

Re: Interview Embedded Software Questions - Arlet - 01:50 17-11-06

42Bastian Schick wrote:

> >Actually, it is
> >s = sqrt(a);
> >C programmer shall know basic standard library functions.
>
> Sorry, failed. Question was: "...squart root of an integer"
> Your solution imposes two castings and pulls in floating point
> arithmetics.

But his solution does produce the square root of an integer, as
requested. The solution is simple, and it works (although you could
complain the result is truncated rather than properly rounded). It
could also allow a smart compiler to recognize it can pull in an
optimized version of integer square root.

If you wanted it optimized, you should have provided more info. What is
the word length, target CPU, required precision, and size/space
constraints ? Do you want it in generic C, or ASM ?


previous | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | next