lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


It was thus said that the Great Sam Roberts once stated:
> On Tue, Mar 8, 2011 at 11:30 AM, liam mail <liam.list@googlemail.com> wrote:
> > Just a note to say that a function pointer and void pointer have
> > no guarantees to be the same size.
> 
> If that is an issue for the OP, don't use lightuserdata, an alternate
> technique is to use the fn ptr value encoded as a hex string.
> 
> While ANSI allows sizeof(void (*)()) to be > sizeof(void*), its pretty
> unusual (I've never seen it). 

  You do have to go back to the MS-DOS days (say, mid-80s, early 90s) for
this to be true.  I don't recall the name of the model, but it wouldn't
surprise me (because of the nature of the 8088 (and 80286) [1] used in PCs if
there wasn't a case where a function pointer was larger than a data pointer. 
Let's see ... 

	tiny	code, data, stack and heap all fit in one 64k segment

	small	code in one 64k segment, data, heap and stack in another 64k
		segment

	???	code in multiple segments, data, heap, stack in one segment

	???	code in one 64k segment, data, heap and stack taking
		multiple segments

	huge	code in multiple segments, data in multiple segments, heap
		in multiple segments, stack (possibly) in multiple segments


  So, depending upon the memory model used by a C compiler on an MS-DOS
system, a void * could be smaller, the same size, or larger than a function
pointer.  If you ever come across old C code with stuff like "NEAR" and
"FAR" associated with pointers, it comes from this era.

  -spc (Glad to be past that point in time ... )

[1]	The 8086/8088/80186/80286 used a segmented architecture where each
	segment was (up to) 64k in size, and there were four segments in use
	at any one time, a code segment (CS), a data segment (DS), a stack
	segment (SS), and an "extra" segment (ES).  Segments could be the
	same (CS = DS = ES = SS) or all separate.  A program could comprise
	more than just four segments; it's just that only a max of four
	would be "visible" at any given moment.