Re: aiuto con gli indicatori

Discussion in 'C Programming' started by Wade Ward, Oct 28, 2007.

  1. Wade Ward

    Wade Ward Guest

    CRAP,

    >>> Sperando di esserte stato chiarificatore!
    >>> Ciao,
    >>> brix
    >>>
    >>>
    >>> "Il Tartaro m'avanza; e il prode ingegno
    >>> Han la tenaria Diva,
    >>> E l'atra notte, e la silente riva. "



    i'VE GOTTA DO THIS.

    WHERE ARE MY GLASSES/

    --
    South Jordan pkwy
    435 -838-7760
    President

    Westates Companies
    Merrill Jensen Consulting
    1108 W. South Jordan pkwy
    42



    Merrill Jensen Consulting
    1108 W. South Jordan pkwy
    435 -838-7760
    President

    Westates Companies
    1108 W. South Jordan pkwy
    435 -838-7760
    President


    "Wade Ward" <> wrote in message
    news:...
    >I just wanted to point out the existence of a "good" top-post.
    >
    > Kathy warned me against this tendency. There is also the other tendency
    > to an n.g. that mixes it wrong. Finally, there is at least one more
    > possible as exemplified by c.l.c.: it is the means by which the uebertroll
    > makes his 6k relevant about what couldn't possibly help the OP as opposed
    > one paragraph of a solution, irrespective of ISO.
    >
    > Below is a translatioin of a technical question that came up in
    > comp.lang.fortran. The man who wrote this english has about as good of
    > english as I have of Russian: in order for this english-ital. translation
    > to work, I, the native pseaker of english, will yet have to proof it.
    > Since OE automatically gives me a copy of what I post, I now have the
    > material in my sent items, so won't have to rely on the internet when I
    > don my reading glasses: +2.5 instead of my current +1.0's.
    >
    > When I've spent some time on it, I'll make a response to this generous
    > Europaen, who helped a yank whom he does not know. Then, I will
    > bottom-post.
    >
    > ciao,
    >
    >
    > --
    > wade ward
    >
    > Westates Companies
    > 1108 W. South Jordan pkwy
    > 435 -838-7760
    > President
    >
    >
    > "Wade Ward" <> wrote in message
    > news:...
    >> Thanks for your response. Looks really good. I'm gonna make one final
    >> edit in the english and hope to post in what I think the answer is in
    >> the lingua france, which, here, in:
    >> it.comp.lang.c
    >>
    >> where the lingua is a little south and east of the francs.
    >>
    >> ciao,
    >>
    >> --
    >> wade ward
    >>
    >> Westates Companies
    >> 1108 W. South Jordan pkwy
    >> 435 -838-7760
    >> President
    >>
    >>
    >> "brix99luftballons" <> wrote in message
    >> news:0cHSi.150273$...
    >>>
    >>> "Wade Ward" <> ha scritto nel messaggio
    >>> news:...
    >>>>
    >>>>



    >>>>> 1. defining a pointer and one integeR type variable
    >>>>> void* pippo; /* This is a pointer*/
    >>>>> long pluto; /* This is an 'integer' */
    >>>>> You can assign the integer value to the pointer, but you have
    >>>>> to recast it:
    >>>>> pippo= (void*)pluto;
    >>>>>
    >>>>> 2. You can assign a pointer to the integer:
    >>>>> pluto=(long)pippo; /* fit a 32bit pointer into a 32bit
    >>>>> integer */
    >>>>
    >>>> caveats:
    >>>>> BUT you must be sure that the whole size of the pointer can fit into
    >>>>> the
    >>>>> integer:
    >>>>> for instance, on a 32bit CPU probably the pointer has a size of 32bit,
    >>>>> so
    >>>>> you
    >>>>> must choice an integer type big enougth to contains a 32bit value.....
    >>>>> char data8;
    >>>>> data8= (char)pippo; /* Legal, but You have only the LSB part of
    >>>>> pointer... */
    >>>>>
    >>>>> data8= pippo; /* Implicit cast, Legal on some compiler, You may
    >>>>> have
    >>>>> a warning .... */
    >>>> good paragraph
    >>>>
    >>>>> This is processor- and compiler-dependent: an int, for instance, on a
    >>>>> 32bit
    >>>>> processor can be a 16bit size variable OR a 32bit size variable,
    >>>>> so You should
    >>>>> better choose a long to hold a 32 bit type as a pointer....
    >>>>> sometimes some types are defined using 'typedef' as int8_t, int16_t,
    >>>>> int32_t etc............
    >>>>> to make more portable the code...
    >>>>> Example:
    >>>>> typedef unsigned char uint8_t; /* 8 bit */
    >>>>> typedef short int16_t; /* 16 bit (On CPU >=16bit, may
    >>>>> be a
    >>>>> 8bit on 8bit CPU) */
    >>>>> typedef int int16_t; /* Ambiguous - 16 bit on
    >>>>> 16bit
    >>>>> CPU or 32bit CPU with some compiler controls */
    >>>>> typedef int int32_t; /* Ambiguous - not valid on 16
    >>>>> bitCPU or 32bit CPU with some compiler controls */
    >>>>> typedef long int32_t; /* 32bit */
    >>>>> Trouble and confusion are bigger using compilers used for embedded
    >>>>> development for little CPU....
    >>>>>
    >>>>> The compiler has a file, limits.h, where you can find some usefull
    >>>>> info.
    >>>>
    >>>>
    >>>>> Some notes: the pointer/integer conversions are *troubling*
    >>>>> operations,
    >>>>> that must
    >>>>> be done only for some very particular operations.
    >>>>> One of such operations involves hardware controls, where sometimes You
    >>>>> have to program
    >>>>> addresses (pointers) in register locations, typically mapped as
    >>>>> 'integer'
    >>>>> types.
    >>>
    >>>>> In such special cases, it may be useful to take just a little part of
    >>>>> the pointer, for intance
    >>>>> only the MSB byte of the pointer, and in such cases the flexibility of
    >>>>> the C is very useful.
    >>>> brix: can you rewrite this last sentence in this paragraph?
    >>>
    >>> Rewrite to make it having sense?



    >>>>>>>>

    arrows err. mpj

    >>> What I want to say is that somethimes it not necessary to get exactly
    >>> the whole address
    >>> of a pointer, but just a part of it. In such case the C (and C++)
    >>> language can helpYou
    >>> very easily, just recasting the pointer to Your integer:
    >>> -----------------
    >>> typedef unsigned long uint32_t;
    >>>
    >>> uint32_t just_a_part_of_ptr;
    >>> void* memPtr;
    >>>
    >>> just_a_part_of_ptr= (((uint32_t)memPtr)>>8); /* Get only the MSN
    >>> 24bit of pointer, discard the LSB8bit */
    >>> just_a_part_of_ptr= (((uint32_t)memPtr)>>16); /* Get only the MSN
    >>> 16bit of pointer, discard the LSB16bit */
    >>> just_a_part_of_ptr= (((uint32_t)memPtr)>>24); /* Get only the MSN
    >>> 8bit of pointer, discard the LSB24bit */
    >>> ----------------
    >>> The question is: well, this is very naive, but for what damned reason I'
    >>> ve to do such thing?
    >>>
    >>> It's a difficult matter to explain....
    >>> I can explain with an example (SIMPLIFIED!):
    >>> I've worked on an hardware that must be fit in the OLD ISA BUS (the one
    >>> used on the original PC -
    >>> This bus is still alive in its PC104 standard incarnation).
    >>> In this architecture, a space in the memory is devoted to expansion
    >>> cards, in the range of 0xA0000 up
    >>> to 0xEFFFF; Now, I'cant explain here the details on the architecture,
    >>> take it just as an example........
    >>> well, because the 'card' decodes its resource in a 32Kbyte of space, I
    >>> need a space of 32768(=0x8000)
    >>> byte locations in memory, so I can use the space from 0xA0000 up to
    >>> 0xA7FFF, or 0xA8000 up to 0xAFFFF
    >>> and so on....
    >>> Because many other cards should be placed on ISA bus, I need to 'maps'
    >>> every one in a different
    >>> space, one mapped in the 0xA0000..0xA7FFF space, another one in the
    >>> 0xA8000...0xAFFFF and
    >>> so on ...otherwise they must conflicts one agaists the other, making
    >>> hardware unusefull.
    >>> (In early day, this was done changing 'jumpers', but now we will do this
    >>> using software..)
    >>> To do this, every card has a 8bit register on board (in IO space) that
    >>> can be write (or read) to assign
    >>> the BASE ADDRESS to use for its own memory resources (call this
    >>> register MAP REGISTER):
    >>> in such register I've to write just only the HIGH PART OF THE ADDRESS:
    >>> to map one board in the
    >>> 0xA0000 space I've to write the (0xA0) part of address, so from the
    >>> pointer address I just take off the
    >>> MSB and put it in the map register.
    >>> -----
    >>> void write_map_register(int board_Number_on_bus, char base_adrr); /*
    >>> just a prototype of function used to write MAP REGISTER */
    >>>
    >>> void* pBoardBase;
    >>> uint32_t reg;
    >>>
    >>> pBoardBase=(void*)(0xD0000); /* Load pointer with new base address-
    >>> Note that is a load of a CONSTANT value... */
    >>>
    >>> ...... some other code ....
    >>>
    >>> write_map_register(boardNum, ((uint32_t)(pBoardBase)>>24) ); /*
    >>> Write BASE address using MSB byte of pointer */
    >>> /* From now on, the board can be controlled writing/reading using
    >>> pBoardBase address... */
    >>> ------
    >>>
    >>> In the reverse, I can read the MAP REGISTER from all the boards and
    >>> rebuild the base pointer of
    >>> each one...
    >>> ---------
    >>> unsigned char read_map_register(int board_Number_on_bus); /* just a
    >>> prototype of function use to read MAP REGISTER */
    >>> void* pBoardBase;
    >>> uint32_t reg;
    >>>
    >>>
    >>> pBoardBase= (void*)( (uint32_t)(read_map_register(boardNum) )<<16);
    >>> /* Get 8bit BASE address and move it to MSB */
    >>> /* Now in pBoardBase I have the pointer used to operate on board ...
    >>> */
    >>> -------
    >>> Of course, this is just an example: there are a lots of devices that
    >>> nedds to be programmed with
    >>> addresses 'converted' into integer type (Thinks to DMA controllers or
    >>> some CPU like the MPC5200 ppc
    >>> that neeeds to program the Chip selectors, for instances, etc...)
    >>>
    >>> What is important to note is that the POINTER<->INTEGER conversion is a
    >>> usefull techique that the
    >>> laguage allows to do easily (it is NOT so easy in all the other
    >>> languages!) , but of course, it mut be
    >>> well undeRstand, otherwise it doNT MEAN SHIT.
    >>>
    >>>
    >>> Just to add more meat FUEL LAME to fire:
    >>> ---------------------------------
    >>> Another way to converts type, without using the recast is the 'union',
    >>> that is a unique and
    >>> powerfull feature of C/C++.
    >>> union can 'map' different types on the same MEMORY LOCATIONS, it's a way
    >>> to view the same piece
    >>> of memory from differents angles, ie as differents variable types:
    >>>
    >>> union {
    >>> void* pBoardBase; /* This is a pointer - 8char size (suppose
    >>> CPU is 32bit) */
    >>> uint32_t u32; /* This is an integer - 8 char size, 32
    >>> bit */
    >>> uint8_t u8[8]; /* This is an array of char - same size
    >>> of u32 */
    >>> uint8_t u8_1[sizeof(uint32_t)]; /* This is an array of char -
    >>> same size of u32, another way to do */
    >>> }x;
    >>> void* myPointer;
    >>>
    >>> x.pBoardBase= myPointer; /* This assign a pointer to a pointer , no
    >>> ned to recast ...*/
    >>>
    >>> x.u32 --> Now contains the same value of x.pBoardBase --> myPointer;
    >>> x.u8 --> Now contains the same value of myPointer !
    >>>
    >>> char p;
    >>> p= u8[7]; /* Now, I've taken the MSB part of pBoardBase on LITTLE
    >>> ENDIAN CPU (1) */
    >>> p= u8[0]; /* Now, I've taken the MSB part of pBoardBase on BIG
    >>> ENDIAN CPU (2) */
    >>>
    >>> (1) On a little endian ordered CPU like Intel x86, otherwhise it is the
    >>> LSB byte
    >>> (2) On a big endian ordered CPU, like Motorola ppc, otherrwhise it is
    >>> the MSB byte

    eNDIANNESS IS SO UEBERBORING, iCAN'T STAND IT.

    >>>> Ringraziamenti per l'elaborazione. Il vostro inglese è molto buono.
    >>>> Have.got il mio compagno Michele che lavora al lato italiano di questo,
    >>>> così, il vostro sommario batterò il tempo fuori di quella traduzione.
    >>>> corteggii woo-hoo.
    >>> [Questa non sono sicuro di averla capita bene... e' un italiano un poco
    >>> bizzarro :) ]
    >>> My English is not so good, but non-english people generally understand
    >>> it enougth... ;-)
    >>>
    >>>>
    >>>> Notte di Beatiful qui nel Nuovo Messico.
    >>>>
    >>>> Salut,
    >>>> --
    >>>> wade ward
    >>>> "Nicht verzagen, Bruder Grinde fragen."
    >>>>


    tHE MOON WAS AT I^ AT 11.15 IN THE PM.

    J_HAT IN 6 HANDS.

    A DAY IS 24.

    This number has unusual utility for algebraists.
    --
    wade ward
    Wade Ward, Oct 28, 2007
    #1
    1. Advertising

  2. Wade Ward

    Wade Ward Guest


    > "Wade Ward" <> wrote in message


    >> Below is a translatioin of a technical question that came up in
    >> comp.lang.fortran. The man who wrote this english has about as good of
    >> english as I have of Russian: in order for this english-ital. translation
    >> to work, I, the native pseaker of english, will yet have to proof it.
    >> Since OE automatically gives me a copy of what I post, I now have the
    >> material in my sent items, so won't have to rely on the internet when I
    >> don my reading glasses: +2.5 instead of my current +1.0's.
    >>
    >> When I've spent some time on it, I'll make a response to this generous
    >> Europaen, who helped a yank whom he does not know. Then, I will
    >> bottom-post.

    Final edit.

    >>>>>> 1. defining a pointer and one integeR type variable
    >>>>>> void* pippo; /* This is a pointer*/
    >>>>>> long pluto; /* This is an 'integer' */
    >>>>>> You can assign the integer value to the pointer, but you have
    >>>>>> to recast it:
    >>>>>> pippo= (void*)pluto;
    >>>>>>
    >>>>>> 2. You can assign a pointer to the integer:
    >>>>>> pluto=(long)pippo; /* fit a 32bit pointer into a 32bit
    >>>>>> integer */
    >>>>>
    >>>>> caveats:
    >>>>>> BUT you must be sure that the whole size of the pointer can fit into
    >>>>>> the
    >>>>>> integer:
    >>>>>> for instance, on a 32bit CPU probably the pointer has a size of
    >>>>>> 32bit, so
    >>>>>> you
    >>>>>> must choice an integer type big enougth to contains a 32bit
    >>>>>> value.....
    >>>>>> char data8;
    >>>>>> data8= (char)pippo; /* Legal, but You have only the LSB part of
    >>>>>> pointer... */
    >>>>>>
    >>>>>> data8= pippo; /* Implicit cast, Legal on some compiler, You may
    >>>>>> have
    >>>>>> a warning .... */
    >>>>> good paragraph

    Still a good paragraph.

    >>>>>> This is processor- and compiler-dependent: an int, for instance, on a
    >>>>>> 32bit
    >>>>>> processor can be a 16bit size variable OR a 32bit size variable,
    >>>>>> so You should
    >>>>>> better choose a long to hold a 32 bit type as a pointer....
    >>>>>> sometimes some types are defined using 'typedef' as int8_t, int16_t,
    >>>>>> int32_t etc............
    >>>>>> to make more portable the code...
    >>>>>> Example:
    >>>>>> typedef unsigned char uint8_t; /* 8 bit */
    >>>>>> typedef short int16_t; /* 16 bit (On CPU >=16bit, may
    >>>>>> be a
    >>>>>> 8bit on 8bit CPU) */
    >>>>>> typedef int int16_t; /* Ambiguous - 16 bit on
    >>>>>> 16bit
    >>>>>> CPU or 32bit CPU with some compiler controls */
    >>>>>> typedef int int32_t; /* Ambiguous - not valid on
    >>>>>> 16
    >>>>>> bitCPU or 32bit CPU with some compiler controls */
    >>>>>> typedef long int32_t; /* 32bit */
    >>>>>> Trouble and confusion are bigger using compilers used for embedded
    >>>>>> development for little CPU....
    >>>>>>
    >>>>>> The compiler has a file, limits.h, where you can find some usefull
    >>>>>> info.
    >>>>>
    >>>>>
    >>>>>> Some notes: the pointer/integer conversions are *troubling*
    >>>>>> operations,
    >>>>>> that must
    >>>>>> be done only for some very particular operations.
    >>>>>> One of such operations involves hardware controls, where sometimes
    >>>>>> You
    >>>>>> have to program
    >>>>>> addresses (pointers) in register locations, typically mapped as
    >>>>>> 'integer'
    >>>>>> types.
    >>>>
    >>>>>> In such special cases, it may be useful to take just a little part
    >>>>>> of
    >>>>>> the pointer, for intance
    >>>>>> only the MSB byte of the pointer, and in such cases the flexibility
    >>>>>> of
    >>>>>> the C is very useful.

    Everything solid in this paragraph.

    >>>> The question is: well, this is very naive, but for what damned reason
    >>>> I' ve to do such thing?
    >>>>
    >>>> It's a difficult matter to explain....
    >>>> I can explain with an example (SIMPLIFIED!):
    >>>> I've worked on an hardware that must be fit in the OLD ISA BUS (the
    >>>> one used on the original PC -
    >>>> This bus is still alive in its PC104 standard incarnation).
    >>>> In this architecture, a space in the memory is devoted to expansion
    >>>> cards, in the range of 0xA0000 up
    >>>> to 0xEFFFF; Now, I'cant explain here the details on the architecture,
    >>>> take it just as an example........
    >>>> well, because the 'card' decodes its resource in a 32Kbyte of space, I
    >>>> need a space of 32768(=0x8000)
    >>>> byte locations in memory, so I can use the space from 0xA0000 up to
    >>>> 0xA7FFF, or 0xA8000 up to 0xAFFFF
    >>>> and so on....
    >>>> Because many other cards should be placed on ISA bus, I need to 'maps'
    >>>> every one in a different
    >>>> space, one mapped in the 0xA0000..0xA7FFF space, another one in the
    >>>> 0xA8000...0xAFFFF and
    >>>> so on ...otherwise they must conflicts one agaists the other, making
    >>>> hardware unusefull.
    >>>> (In early day, this was done changing 'jumpers', but now we will do
    >>>> this using software..)
    >>>> To do this, every card has a 8bit register on board (in IO space) that
    >>>> can be write (or read) to assign
    >>>> the BASE ADDRESS to use for its own memory resources (call this
    >>>> register MAP REGISTER):
    >>>> in such register I've to write just only the HIGH PART OF THE ADDRESS:
    >>>> to map one board in the
    >>>> 0xA0000 space I've to write the (0xA0) part of address, so from the
    >>>> pointer address I just take off the
    >>>> MSB and put it in the map register.
    >>>> -----
    >>>> void write_map_register(int board_Number_on_bus, char base_adrr);
    >>>> /* just a prototype of function used to write MAP REGISTER */
    >>>>
    >>>> void* pBoardBase;
    >>>> uint32_t reg;
    >>>>
    >>>> pBoardBase=(void*)(0xD0000); /* Load pointer with new base address-
    >>>> Note that is a load of a CONSTANT value... */
    >>>>
    >>>> ...... some other code ....
    >>>>
    >>>> write_map_register(boardNum, ((uint32_t)(pBoardBase)>>24) ); /*
    >>>> Write BASE address using MSB byte of pointer */
    >>>> /* From now on, the board can be controlled writing/reading using
    >>>> pBoardBase address... */
    >>>> ------
    >>>>
    >>>> In the reverse, I can read the MAP REGISTER from all the boards and
    >>>> rebuild the base pointer of
    >>>> each one...
    >>>> ---------
    >>>> unsigned char read_map_register(int board_Number_on_bus); /* just a
    >>>> prototype of function use to read MAP REGISTER */
    >>>> void* pBoardBase;
    >>>> uint32_t reg;
    >>>>
    >>>>
    >>>> pBoardBase= (void*)( (uint32_t)(read_map_register(boardNum) )<<16);
    >>>> /* Get 8bit BASE address and move it to MSB */
    >>>> /* Now in pBoardBase I have the pointer used to operate on board ...
    >>>> */
    >>>> -------
    >>>> Of course, this is just an example: there are a lots of devices that
    >>>> nedds to be programmed with
    >>>> addresses 'converted' into integer type (Thinks to DMA controllers or
    >>>> some CPU like the MPC5200 ppc
    >>>> that neeeds to program the Chip selectors, for instances, etc...)
    >>>>
    >>>> What is important to note is that the POINTER<->INTEGER conversion is
    >>>> a usefull techique that the
    >>>> laguage allows to do easily (it is NOT so easy in all the other
    >>>> languages!) , but of course, it mut be
    >>>> well undeRstand, otherwise it doNT MEAN SHIT.
    >>>>
    >>>>
    >>>> Just to add more meat FUEL LAME to fire:
    >>>> ---------------------------------
    >>>> Another way to converts type, without using the recast is the 'union',
    >>>> that is a unique and
    >>>> powerfull feature of C/C++.
    >>>> union can 'map' different types on the same MEMORY LOCATIONS, it's a
    >>>> way to view the same piece
    >>>> of memory from differents angles, ie as differents variable types:
    >>>>
    >>>> union {
    >>>> void* pBoardBase; /* This is a pointer - 8char size (suppose
    >>>> CPU is 32bit) */
    >>>> uint32_t u32; /* This is an integer - 8 char size,
    >>>> 32 bit */
    >>>> uint8_t u8[8]; /* This is an array of char - same
    >>>> size of u32 */
    >>>> uint8_t u8_1[sizeof(uint32_t)]; /* This is an array of char -
    >>>> same size of u32, another way to do */
    >>>> }x;
    >>>> void* myPointer;
    >>>>
    >>>> x.pBoardBase= myPointer; /* This assign a pointer to a pointer , no
    >>>> ned to recast ...*/
    >>>>
    >>>> x.u32 --> Now contains the same value of x.pBoardBase --> myPointer;
    >>>> x.u8 --> Now contains the same value of myPointer !
    >>>>
    >>>> char p;
    >>>> p= u8[7]; /* Now, I've taken the MSB part of pBoardBase on LITTLE
    >>>> ENDIAN CPU (1) */
    >>>> p= u8[0]; /* Now, I've taken the MSB part of pBoardBase on BIG
    >>>> ENDIAN CPU (2) */
    >>>>
    >>>> (1) On a little endian ordered CPU like Intel x86, otherwhise it is the
    >>>> LSB byte
    >>>> (2) On a big endian ordered CPU, like Motorola ppc, otherrwhise it is
    >>>> the MSB byte

    > eNDIANNESS IS SO UEBERBORING, iCAN'T STAND IT.

    Implementation-dependent behavior. It is to avoid the above that we have
    the standard.

    >>> "brix99luftballons" <> wrote in message
    >>> news:0cHSi.150273$...

    Dann singe ich ein Lied für Dich von
    99 Luftballoons,
    in ihrem Weg zum Horizont.

    Denkst Du vielleicht, gerad' an mich
    Dann singe ich ein Lied für Dich
    Und daß sowas von sowas kommt....


    >>>> What I want to say is that somethimes it not necessary to get exactly
    >>>> the whole address
    >>>> of a pointer, but just a part of it. In such case the C (and C++)
    >>>> language can helpYou
    >>>> very easily, just recasting the pointer to Your integer:
    >>>> -----------------
    >>>> typedef unsigned long uint32_t;
    >>>>
    >>>> uint32_t just_a_part_of_ptr;
    >>>> void* memPtr;
    >>>>
    >>>> just_a_part_of_ptr= (((uint32_t)memPtr)>>8); /* Get only the MSN
    >>>> 24bit of pointer, discard the LSB8bit */
    >>>> just_a_part_of_ptr= (((uint32_t)memPtr)>>16); /* Get only the MSN
    >>>> 16bit of pointer, discard the LSB16bit */
    >>>> just_a_part_of_ptr= (((uint32_t)memPtr)>>24); /* Get only the MSN
    >>>> 8bit of pointer, discard the LSB24bit */
    >>>> ----------------

    More tricky situations. I don't understand the technical part of this
    paragraph. Tja,

    and ciao,
    --
    wade ward

    President

    Westates Companies
    Merrill Jensen Consulting
    Wade Ward, Oct 29, 2007
    #2
    1. Advertising

  3. Wade Ward

    Wade Ward Guest

    I just wanted to point out the existence of a "good" top-post.

    Kathy warned me against this tendency. There is also the other tendency to
    an n.g. that mixes it wrong. Finally, there is at least one more possible
    as exemplified by c.l.c.: it is the means by which the uebertroll makes his
    6k relevant about what couldn't possibly help the OP as opposed one
    paragraph of a solution, irrespective of ISO.

    Below is a translatioin of a technical question that came up in
    comp.lang.fortran. The man who wrote this english has about as good of
    english as I have of Russian: in order for this english-ital. translation to
    work, I, the native pseaker of english, will yet have to proof it. Since OE
    automatically gives me a copy of what I post, I now have the material in my
    sent items, so won't have to rely on the internet when I don my reading
    glasses: +2.5 instead of my current +1.0's.

    When I've spent some time on it, I'll make a response to this generous
    Europaen, who helped a yank whom he does not know. Then, I will
    bottom-post.

    ciao,


    --
    wade ward

    Westates Companies
    1108 W. South Jordan pkwy
    435 -838-7760
    President


    "Wade Ward" <> wrote in message
    news:...
    > Thanks for your response. Looks really good. I'm gonna make one final
    > edit in the english and hope to post in what I think the answer is in the
    > lingua france, which, here, in:
    > it.comp.lang.c
    >
    > where the lingua is a little south and east of the francs.
    >
    > ciao,
    >
    > --
    > wade ward
    >
    > Westates Companies
    > 1108 W. South Jordan pkwy
    > 435 -838-7760
    > President
    >
    >
    > "brix99luftballons" <> wrote in message
    > news:0cHSi.150273$...
    >>
    >> "Wade Ward" <> ha scritto nel messaggio
    >> news:...
    >>>
    >>>
    >>> "brix" <> wrote in message
    >>> news:qBYRi.661$...
    >>>>
    >>>>
    >>>> Wade Ward ha scritto:
    >>>>> "nano bagonghi" <> wrote in message
    >>>>> news:47177483$0$17952$...
    >>>>>
    >>>>>> Wade Ward wrote:
    >>>>>>
    >>>>>>
    >>>>>>
    >>>>>>> Thanks for your reply. I couldn't save my life to speak Italian,
    >>>>>>> unless the topic is wine or well-grown tomatoes.
    >>> Or basketball. It's nice that italians can hoop.
    >>>
    >>> [wade is proofing:]
    >>>> In such case, You have to specify that You do not spoke italian ;-)
    >>>> BTW, general speaking about pointers and recasting...
    >>>> in C You can assign a pointer to any other types, and vice-versa.
    >>>> Of course not all the possible operations may make sense
    >>>> ................
    >>>>
    >>>> 1. defining a pointer and one integet type variable
    >>>> void* pippo; /* This is a pointer*/
    >>>> long pluto; /* This is an 'integer' */
    >>>> You can assign the integer value to the pointer, but you have
    >>>> to recast it:
    >>>> pippo= (void*)pluto;
    >>>>
    >>>> 2. You can assign a pointer to the integer:
    >>>> pluto=(long)pippo; /* fit a 32bit pointer into a 32bit
    >>>> integer */
    >>>
    >>> caveats:
    >>>> BUT you must be sure that the whole size of the pointer can fit into
    >>>> the
    >>>> integer:
    >>>> for instance, on a 32bit CPU probably the pointer has a size of 32bit,
    >>>> so
    >>>> you
    >>>> must choice an integer type big enougth to contains a 32bit value.....
    >>>> char data8;
    >>>> data8= (char)pippo; /* Legal, but You have only the LSB part of
    >>>> pointer... */
    >>>>
    >>>> data8= pippo; /* Implicit cast, Legal on some compiler, You may
    >>>> have
    >>>> a warning .... */
    >>> good paragraph
    >>>
    >>>> This is processor- and compiler-dependent: an int, for instance, on a
    >>>> 32bit
    >>>> processor can be a 16bit size variable OR a 32bit size variable,
    >>>> so You should
    >>>> better choose a long to hold a 32 bit type as a pointer....
    >>>> sometimes some types are defined using 'typedef' as int8_t, int16_t,
    >>>> int32_t etc............
    >>>> to make more portable the code...
    >>>> Example:
    >>>> typedef unsigned char uint8_t; /* 8 bit */
    >>>> typedef short int16_t; /* 16 bit (On CPU >=16bit, may be
    >>>> a
    >>>> 8bit on 8bit CPU) */
    >>>> typedef int int16_t; /* Ambiguous - 16 bit on 16bit
    >>>> CPU or 32bit CPU with some compiler controls */
    >>>> typedef int int32_t; /* Ambiguous - not valid on 16
    >>>> bitCPU or 32bit CPU with some compiler controls */
    >>>> typedef long int32_t; /* 32bit */
    >>>> Trouble and confusion are bigger using compilers used for embedded
    >>>> development for little CPU....
    >>>>
    >>>> The compiler has a file, limits.h, where you can find some usefull
    >>>> info.
    >>>
    >>>
    >>>> Some notes: the pointer/integer conversions are *troubling* operations,
    >>>> that must
    >>>> be done only for some very particular operations.
    >>>> One of such operations involves hardware controls, where sometimes You
    >>>> have to program
    >>>> addresses (pointers) in register locations, typically mapped as
    >>>> 'integer'
    >>>> types.

    >>
    >>>> In such special cases, it may be useful to take just a little part of
    >>>> the pointer, for intance
    >>>> only the MSB byte of the pointer, and in such cases the flexibility of
    >>>> the C is very useful.
    >>> brix: can you rewrite this last sentence in this paragraph?

    >>
    >> Rewrite to make it having sense?
    >> What I want to say is that somethimes it not necessary to get exactly the
    >> whole address
    >> of a pointer, but just a part of it. In such case the C (and C++)
    >> language can helpYou
    >> very easily, just recasting the pointer to Your integer:
    >> -----------------
    >> typedef unsigned long uint32_t;
    >>
    >> uint32_t just_a_part_of_ptr;
    >> void* memPtr;
    >>
    >> just_a_part_of_ptr= (((uint32_t)memPtr)>>8); /* Get only the MSN
    >> 24bit of pointer, discard the LSB8bit */
    >> just_a_part_of_ptr= (((uint32_t)memPtr)>>16); /* Get only the MSN
    >> 16bit of pointer, discard the LSB16bit */
    >> just_a_part_of_ptr= (((uint32_t)memPtr)>>24); /* Get only the MSN
    >> 8bit of pointer, discard the LSB24bit */
    >> ----------------
    >> The question is: well, this is very naive, but for what damned reason I'
    >> ve to do such thing?
    >>
    >> It's a difficult matter to explain....
    >> I can explain with an example (SIMPLIFIED!):
    >> I've worked on an hardware that must be fit in the OLD ISA BUS (the one
    >> used on the original PC -
    >> This bus is still alive in its PC104 standard incarnation).
    >> In this architecture, a space in the memory is devoted to expansion
    >> cards, in the range of 0xA0000 up
    >> to 0xEFFFF; Now, I'cant explain here the details on the architecture,
    >> take it just as an example........
    >> well, because the 'card' decodes its resource in a 32Kbyte of space, I
    >> need a space of 32768(=0x8000)
    >> byte locations in memory, so I can use the space from 0xA0000 up to
    >> 0xA7FFF, or 0xA8000 up to 0xAFFFF
    >> and so on....
    >> Because many other cards should be placed on ISA bus, I need to 'maps'
    >> every one in a different
    >> space, one mapped in the 0xA0000..0xA7FFF space, another one in the
    >> 0xA8000...0xAFFFF and
    >> so on ...otherwise they must conflicts one agaists the other, making
    >> hardware unusefull.
    >> (In early day, this was done changing 'jumpers', but now we will do this
    >> using software..)
    >> To do this, every card has a 8bit register on board (in IO space) that
    >> can be write (or read) to assign
    >> the BASE ADDRESS to use for its own memory resources (call this register
    >> MAP REGISTER):
    >> in such register I've to write just only the HIGH PART OF THE ADDRESS: to
    >> map one board in the
    >> 0xA0000 space I've to write the (0xA0) part of address, so from the
    >> pointer address I just take off the
    >> MSB and put it in the map register.
    >> -----
    >> void write_map_register(int board_Number_on_bus, char base_adrr); /*
    >> just a prototype of function used to write MAP REGISTER */
    >>
    >> void* pBoardBase;
    >> uint32_t reg;
    >>
    >> pBoardBase=(void*)(0xD0000); /* Load pointer with new base address-
    >> Note that is a load of a CONSTANT value... */
    >>
    >> ...... some other code ....
    >>
    >> write_map_register(boardNum, ((uint32_t)(pBoardBase)>>24) ); /*
    >> Write BASE address using MSB byte of pointer */
    >> /* From now on, the board can be controlled writing/reading using
    >> pBoardBase address... */
    >> ------
    >>
    >> In the reverse, I can read the MAP REGISTER from all the boards and
    >> rebuild the base pointer of
    >> each one...
    >> ---------
    >> unsigned char read_map_register(int board_Number_on_bus); /* just a
    >> prototype of function use to read MAP REGISTER */
    >> void* pBoardBase;
    >> uint32_t reg;
    >>
    >>
    >> pBoardBase= (void*)( (uint32_t)(read_map_register(boardNum) )<<16); /*
    >> Get 8bit BASE address and move it to MSB */
    >> /* Now in pBoardBase I have the pointer used to operate on board ... */
    >> -------
    >> Of course, this is just an example: there are a lots of devices that
    >> nedds to be programmed with
    >> addresses 'converted' into integer type (Thinks to DMA controllers or
    >> some CPU like the MPC5200 ppc
    >> that neeeds to program the Chip selectors, for instances, etc...)
    >>
    >> What is important to note is that the POINTER<->INTEGER conversion is a
    >> usefull techique that the
    >> laguage allows to do easily (it is NOT so easy in all the other
    >> languages!) , but of course, it mut be
    >> well undestand, otherwise it do not have any meanings.
    >>
    >>
    >> Just to add more meat to fire:
    >> ---------------------------------
    >> Another way to converts type, without using the recast is the 'union',
    >> that is a unique and
    >> powerfull feature of C/C++.
    >> union can 'map' different types on the same MEMORY LOCATIONS, it's a way
    >> to view the same piece
    >> of memory from differents angles, ie as differents variable types:
    >>
    >> union {
    >> void* pBoardBase; /* This is a pointer - 8char size (suppose
    >> CPU is 32bit) */
    >> uint32_t u32; /* This is an integer - 8 char size, 32
    >> bit */
    >> uint8_t u8[8]; /* This is an array of char - same size
    >> of u32 */
    >> uint8_t u8_1[sizeof(uint32_t)]; /* This is an array of char -
    >> same size of u32, another way to do */
    >> }x;
    >> void* myPointer;
    >>
    >> x.pBoardBase= myPointer; /* This assign a pointer to a pointer , no ned
    >> to recast ...*/
    >>
    >> x.u32 --> Now contains the same value of x.pBoardBase --> myPointer;
    >> x.u8 --> Now contains the same value of myPointer !
    >>
    >> char p;
    >> p= u8[7]; /* Now, I've taken the MSB part of pBoardBase on LITTLE
    >> ENDIAN CPU (1) */
    >> p= u8[0]; /* Now, I've taken the MSB part of pBoardBase on BIG
    >> ENDIAN CPU (2) */
    >>
    >> (1) On a little endian ordered CPU like Intel x86, otherwhise it is the
    >> LSB byte
    >> (2) On a big endian ordered CPU, like Motorola ppc, otherrwhise it is the
    >> MSB byte
    >>
    >>
    >>>
    >>> Ringraziamenti per l'elaborazione. Il vostro inglese è molto buono.
    >>> Have.got il mio compagno Michele che lavora al lato italiano di questo,
    >>> così, il vostro sommario batterò il tempo fuori di quella traduzione.
    >>> corteggii woo-hoo.

    >> [Questa non sono sicuro di averla capita bene... e' un italiano un poco
    >> bizzarro :) ]
    >> My English is not so good, but non-english people generally understand it
    >> enougth... ;-)
    >>
    >>>
    >>> Notte di Beatiful qui nel Nuovo Messico.
    >>>
    >>> Salut,
    >>> --
    >>> wade ward
    >>> "Nicht verzagen, Bruder Grinde fragen."
    >>>

    >> Sperando di esserte stato chiarificatore!
    >> Ciao,
    >> brix
    >>
    >>
    >> "Il Tartaro m'avanza; e il prode ingegno
    >> Han la tenaria Diva,
    >> E l'atra notte, e la silente riva. "
    >>
    >>

    >
    >
    Wade Ward, Nov 26, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Liber
    Replies:
    4
    Views:
    4,740
    Tristan
    Sep 6, 2004
  2. kronos

    Aiuto!

    kronos, Nov 8, 2005, in forum: Java
    Replies:
    4
    Views:
    610
    Roedy Green
    Nov 9, 2005
  3. ciccio

    aiuto j2me bluetooth

    ciccio, Mar 22, 2006, in forum: Java
    Replies:
    1
    Views:
    933
    David N. Welton
    Mar 22, 2006
  4. Replies:
    4
    Views:
    4,152
  5. Matteo Mancini

    Piccolo con problema con il tipo float

    Matteo Mancini, Oct 8, 2007, in forum: Ruby
    Replies:
    3
    Views:
    191
    Jano Svitok
    Oct 8, 2007
Loading...

Share This Page