1. general c library question
- Posted by Chris Burch <chriscrylex at aol.com> Jan 26, 2006
- 552 views
- Last edited Jan 27, 2006
Hi In the c library #define NCURSES_ATTR_SHIFT 8 or #define NCURSES_BITS(mask,shift) ((mask) << ((shift) + NCURSES_ATTR_SHIFT)) #define A_COLOR NCURSES_BITS(((1UL) << 8) - 1UL,0) How do I access NCURSES_ATTR_SHIFT, or A_COLOR. A_COLOR looks like a macro, whereas NCURSES_ATTR_SHIFT is obviously a variable, but
global constant NAS = peek4u(define_c_var(ncurses_so, "NCURSES_ATTR_SHIFT"))
gives me a machine level exception As ever, help greatly appreciated Chris http://members.aol.com/chriscrylex/euphoria.htm http://uboard.proboards32.com/ http://members.aol.com/chriscrylex/EUSQLite/eusql.html
2. Re: general c library question
- Posted by Alexander Toresson <alexander.toresson at gmail.com> Jan 26, 2006
- 558 views
- Last edited Jan 27, 2006
Chris Burch wrote: > > Hi > > In the c library > > #define NCURSES_ATTR_SHIFT 8 > > or > > #define NCURSES_BITS(mask,shift) ((mask) << ((shift) + NCURSES_ATTR_SHIFT)) > #define A_COLOR NCURSES_BITS(((1UL) << 8) - 1UL,0) > > How do I access NCURSES_ATTR_SHIFT, or A_COLOR. > > A_COLOR looks like a macro, whereas NCURSES_ATTR_SHIFT is obviously a > variable, > but > > }}} <eucode> > global constant > NAS = peek4u(define_c_var(ncurses_so, "NCURSES_ATTR_SHIFT")) > </eucode> {{{ > > gives me a machine level exception > > As ever, help greatly appreciated > > Chris > All three are macros, and as such they don't exist as variables or functions. The preprocessor just replaces any occurence of NCURSES_ATTR_SHIFT with 8 and NCURSES_BITS(foo,bar) with ((foo) << ((bar) + 8)). Regards, Alexander Toresson
3. Re: general c library question
- Posted by Ed Davis <ed_davis2 at yahoo.com> Jan 26, 2006
- 544 views
- Last edited Jan 27, 2006
Chris Burch wrote: >In the c library > >#define NCURSES_ATTR_SHIFT 8 > >or > >#define NCURSES_BITS(mask,shift) ((mask) << ((shift) + NCURSES_ATTR_SHIFT)) >#define A_COLOR NCURSES_BITS(((1UL) << 8) - 1UL,0) > >How do I access NCURSES_ATTR_SHIFT, or A_COLOR. > >A_COLOR looks like a macro, whereas NCURSES_ATTR_SHIFT is obviously a >variable, but > >global constant >NAS = peek4u(define_c_var(ncurses_so, "NCURSES_ATTR_SHIFT")) > >gives me a machine level exception You can't access them from Euphoria, because they aren't there These are macros, and so at compile time, wherever NCURSES_ATTR_SHIFT is referenced, it simply becomes 8. A_COLOR becomes 0xff00 - I think So, you'll have to just define a constant in your code, and hope the ncurses code doesn't change By the way, I think it is cool that you're wrapped ncurses. Good job! Now that ncurses isn't really needed (what with the new version coming that doesn't included it), we can use a better () console library such as slang or better yet, TxWin - http://svn.netlabs.org/txwin - works in 32-bit DOS, Windows, and Linux. Made for Watcom too!
4. Re: general c library question
- Posted by Jason Gade <jaygade at yahoo.com> Jan 26, 2006
- 539 views
- Last edited Jan 27, 2006
Chris Burch wrote: > > Hi > > In the c library > > #define NCURSES_ATTR_SHIFT 8 > > or > > #define NCURSES_BITS(mask,shift) ((mask) << ((shift) + NCURSES_ATTR_SHIFT)) > #define A_COLOR NCURSES_BITS(((1UL) << 8) - 1UL,0) > > How do I access NCURSES_ATTR_SHIFT, or A_COLOR. > > A_COLOR looks like a macro, whereas NCURSES_ATTR_SHIFT is obviously a > variable, > but > > }}} <eucode> > global constant > NAS = peek4u(define_c_var(ncurses_so, "NCURSES_ATTR_SHIFT")) > </eucode> {{{ > > gives me a machine level exception > > As ever, help greatly appreciated > > Chris > > > <a > href="http://members.aol.com/chriscrylex/euphoria.htm">http://members.aol.com/chriscrylex/euphoria.htm</a> > <a href="http://uboard.proboards32.com/">http://uboard.proboards32.com/</a> > <a > href="http://members.aol.com/chriscrylex/EUSQLite/eusql.html">http://members.aol.com/chriscrylex/EUSQLite/eusql.html</a> Not an expert, but here is my take: All #defines in C are macros. Every instance of the macro is replaced by its value. Therefore, NCURSES_ATTR_SHIFT is not a variable, but just a substitution for the number 8. The C preprocessor goes through the source and replaces every instance of NCURSES_ATTR_SHIFT with the number 8, before the compiler even gets to the source. The macros NCURSES_BITS(mask,shift) and A_COLOR basically inline an expression where ever they are found, replacing the string A_COLOR with the expression and simple variable substitution. So in that context,
NAS = peek4u(define_c_var(ncurses_so, "NCURSES_ATTR_SHIFT")
doesn't make any sense. There is no identifier of that name in the so. Just think of them as constants. Euphoria constants cannot act like macro substitutions for expressions, but you can write a function for them.
constant NCURSES_ATTR_SHIFT = 8 function NCURSES_BITS(atom mask, integer shift) return mask * power(2, (shift + NCURSES_ATTR_SHIFT)) end function -- 1UL is just 1, multiply by 256, subtract 1. -- Remember, the function shifts by 'shift' + 8 constant A_COLOR = NCURSES_BITS(255, 0) -- should be 65280
The C preprocessor is a very simple beast, and very literal, though it seems to me a lot of people do some wierd/advanced stuff with it. HTH -- "The author regrets that he is unable to reconcile himself to the thoughtful point of view you have expressed. However, it must be kept in mind that being raised in different cultures and different places can result in such differences of viewpoint between individuals. The author is from planet Earth." [author unknown] j.
5. Re: general c library question
- Posted by Kenneth Rhodes <ken_rhodes30436 at yahoo.com> Jan 26, 2006
- 549 views
- Last edited Jan 27, 2006
Ed Davis wrote: > > Now that ncurses isn't really needed (what with the new version coming > that doesn't included it), we can use a better () console library > such as slang or better yet, TxWin > http://svn.netlabs.org/txwin > works in 32-bit DOS, Windows, and Linux. Made for Watcom too! So, will Rob just ship one version of *Nix Eu without ncurses and then those who want to use it will include it separately? Will/should/could TxWin be wrapped in the same manner as ncurses? Will leaving ncurses out of the interpreter render any improvement in overall speed? Considering overwhelming popularity of GUI's ( Windows, WxWidgets, GTK ) would it be wise for Robert to leave such libraries as ncurses and TxWin out of the Euphoria interpreter all together.... or Since TxWin is crossplatform, drop ncurses and use TxWin in all versions of Eu? Lots of interesting stuff happening here - thanks to Chris Burch for wrapping ncurses! Ken Rhodes 100% MicroSoft Free SuSE Linux 10.0 No AddWare, SpyWare, or Viruses! Life is Good :)
6. Re: general c library question
- Posted by Greg Haberek <ghaberek at gmail.com> Jan 26, 2006
- 554 views
- Last edited Jan 27, 2006
> #define NCURSES_ATTR_SHIFT 8
global constant NCURSES_ATTR_SHIFT = 8
> #define NCURSES_BITS(mask,shift) ((mask) << ((shift) + NCURSES_ATTR_SHIFT= )) > #define A_COLOR NCURSES_BITS(((1UL) << 8) - 1UL,0)
function shift_left( atom x, integer bits ) return x * power( 2, bits ) end function global function NCURSES_BITS( integer mask, integer shift ) return shift_left( mask, shift + NCURSES_ATTR_SHIFT ) end function global constant A_COLOR = NCURSES_BITS( shift_left(1, 8) - 1, 0)
~Greg
7. Re: general c library question
- Posted by Chris Burch <chriscrylex at aol.com> Jan 26, 2006
- 529 views
- Last edited Jan 27, 2006
Hi Thanks to all who replied - stupid me, and thanks for that piece of code Greg. Txwin looks nice. Unfortunately, I'm a very slow coder, and I have other 'demands' on my time - my goal is to wrap and test one or two functions a day. One small point - what does the community think about whether to ref the screen / window coordinates from 0, as in C, or from 1, as in eu, or should I make it a switchable option, ie global integer SET_REF_FROM SET_REF_FROM = 1 --eu type then the coder could in his or her program SET_REF_FROM = 0 --set to C type referencing Chris http://members.aol.com/chriscrylex/euphoria.htm http://uboard.proboards32.com/ http://members.aol.com/chriscrylex/EUSQLite/eusql.html
8. Re: general c library question
- Posted by D. Newhall <derek_newhall at yahoo.com> Jan 26, 2006
- 544 views
- Last edited Jan 27, 2006
Chris Burch wrote: (snip) > One small point - what does the community think about whether to ref the > screen > / window coordinates from 0, as in C, or from 1, as in eu, or should I make > it a switchable option, ie > > global integer SET_REF_FROM > SET_REF_FROM = 1 --eu type > > then the coder could in his or her program > SET_REF_FROM = 0 --set to C type referencing Switchable. From Euphoria I expect (and prefer) indeces starting at 1 but if I'm porting C code to Eu I would have to make sure to convert all the indeces as well which would take time and probably introduce errors (and since there are many programs that use ncurses people might be doing this a lot). If you decide not to make it switchable use 1 since "x = array[0]" produces an error in Euphoria whereas if you use indeces starting at 0 "x = array[1]" would be valid but wrong (and would probably be a common mistake). The Euphoria Standard Library project : http://esl.sourceforge.net/ The Euphoria Standard Library mailing list : https://lists.sourceforge.net/lists/listinfo/esl-discussion
9. Re: general c library question
- Posted by Jason Gade <jaygade at yahoo.com> Jan 27, 2006
- 548 views
Chris Burch wrote: > > Hi > > Thanks to all who replied - stupid me, and thanks for that piece of code Greg. > > Txwin looks nice. > > Unfortunately, I'm a very slow coder, and I have other 'demands' on my time > - my goal is to wrap and test one or two functions a day. > > One small point - what does the community think about whether to ref the > screen > / window coordinates from 0, as in C, or from 1, as in eu, or should I make > it a switchable option, ie > > global integer SET_REF_FROM > SET_REF_FROM = 1 --eu type > > then the coder could in his or her program > SET_REF_FROM = 0 --set to C type referencing > > Chris > > > <a > href="http://members.aol.com/chriscrylex/euphoria.htm">http://members.aol.com/chriscrylex/euphoria.htm</a> > <a href="http://uboard.proboards32.com/">http://uboard.proboards32.com/</a> > <a > href="http://members.aol.com/chriscrylex/EUSQLite/eusql.html">http://members.aol.com/chriscrylex/EUSQLite/eusql.html</a> For coordinate purposes, I like 0-based counting better. I doubt if I'll use the library, though. But just expressing my opinion. I've found that it doesn't matter much if you use one-based or zero-based for a lot of things; you'll eventually have to add or subtract 1 in certain algorithms anyway. Zero-based is better for things that are offset from some base; one-based is better for cardinal counting (1st, 2nd, 3rd, etc.) -- "The author regrets that he is unable to reconcile himself to the thoughtful point of view you have expressed. However, it must be kept in mind that being raised in different cultures and different places can result in such differences of viewpoint between individuals. The author is from planet Earth." [author unknown] j.