Keil™, An ARM® Company

Discussion Forum

void pointer

Next Thread | Thread List | Previous Thread Start a Thread | Settings

DetailsMessage
Read-Only
Author
techven khsl
Posted
23-Dec-2004 11:41 GMT
Toolset
C51
New! void pointer
Hi,

Any idea what does following do and how ?

((void (code *) (void)) 0) ();

Any help would be great
Read-Only
Author
A.W. Neil
Posted
23-Dec-2004 11:48 GMT
Toolset
C51
New! RE: void pointer
Apart from the Keil-specific 'code' keyword, it's standard 'C' - see your 'C' textbook.

For the Keil-specific 'code' keyword, see the Keil C51 Manual.
Read-Only
Author
Jay Daniel
Posted
23-Dec-2004 14:27 GMT
Toolset
C51
New! RE: void pointer
techven,

It's still early, so spare me the tirade if I screw this up, but here goes:

What this snippet of code is probably meant to do (in short form) is reset the processor (or at least jump code execution to address 0 so it can jump to the start of the application).

Andy's right that this is all standard C, but just start from the 0 (the only value in the statement) and look at the casts. The value is cast to a pointer (in code memory, in this case) to a function returning void and taking no parameters (although the author put in an extra "void" for clarity). After this cast, the function at that location is "called" with the (); which will do what I described above.
Read-Only
Author
A.W. Neil
Posted
23-Dec-2004 14:52 GMT
Toolset
C51
New! RE: void pointer
"What this snippet of code is probably meant to do (in short form) is reset the processor (or at least jump code execution to address 0 so it can jump to the start of the application)."

As Jay so carefully says, that may be what it's meant to do; but note that jumping to code address 0x0000 is not the same thing as resetting the processor - by a long way.

A true reset will reset the chip hardware and then restart the software from code address 0x0000.

Simply jumping to code address 0x0000 will leave the chip hardware in an indeterminate state when the software restarts.

If you need to do a reset, the best way is to use a watchdog and just let it time-out.

There's been plenty of discussion of this - try a 'Search'
Read-Only
Author
Jay Daniel
Posted
23-Dec-2004 15:02 GMT
Toolset
C51
New! RE: void pointer
I have to agree with Andy. Now that you know what this author was trying to do, the best thing for YOU to do is something entirely different. For instance, if this is done in an interrupt service routine, you're almost certainly going to have a screwed up system after this quasi-reset. And no matter where it's called from, you'll have to take care of the stack pointer, etc. to get things back to the correct state. The best way to reset will always be to turn on the watchdog and then just throw a while(1); in the code and wait for a proper reset.
Read-Only
Author
Dan Henry
Posted
23-Dec-2004 15:27 GMT
Toolset
C51
New! RE: void pointer
"... what this author was trying to do ..."

Now this author needs to figure out what processor and toolchain he/she is dealing with.

http://www.htsoft.com/forum/all/showflat.php/Cat/0/Number/15018/an/0/page/0#15018
Read-Only
Author
Jay Daniel
Posted
23-Dec-2004 15:47 GMT
Toolset
C51
New! RE: void pointer
Hehe... good find Dan. It must be a bit galling to see a bunch of posts to the effect of "don't do what this hack is doing" when you wrote the code yourself. So it goes...
Read-Only
Author
Jon Ward
Posted
23-Dec-2004 16:38 GMT
Toolset
C51
New! RE: void pointer
I think there's a more interesting point in all of this. There are no replies on the HiTech forum except Dan's. There are six replies on the Keil forum.

What meaning can we read into this?

  • Software developers using HiTech tools are already celebrating Christmas and not answering forum questions?
  • Software developers using Keil do not celebrate Christmas?
  • HiTech developers are just now starting to shop for Christmas gifts and don't have time to answer forum queries?
  • Keil developers are already celebrating Christmas, have already bought gifts, and after 15 minutes with the relatives are bored and have started web surfing?
Either way, have a Merry Christmas.

Jon
Read-Only
Author
Stefan Duncanson
Posted
23-Dec-2004 16:56 GMT
Toolset
C51
New! RE: void pointer
Do you really celebrate Xmas in October?
Read-Only
Author
Dan Henry
Posted
23-Dec-2004 17:14 GMT
Toolset
C51
New! RE: void pointer
"What meaning can we read into this?"

Corroborates the viewpoint favoring the 8051 in the 8051-vs-PIC market share debates?
Read-Only
Author
Keil Reinhard
Posted
4-Jan-2005 17:17 GMT
Toolset
C51
New! RE: void pointer
Even at Christmas time search at http://www.keil.com/support works. Entering "void code" gives several useful answers. Item 7 is: http://www.keil.com/support/docs/307.htm

This perfectly answers the initial question.

Next Thread | Thread List | Previous Thread Start a Thread | Settings