Re: Working with unsigned/signed types

Discussion in 'Python' started by Ben Finney, Dec 20, 2006.

  1. Ben Finney

    Ben Finney Guest

    <> writes:

    > The first part of the question is fairly basic - in C, working with
    > signed integers, the MSB (is that still the right term?) is used to
    > denote positive and negative, and the following bits increase
    > towards positive infinity, correct? Such that in C, adding one to
    > 0x7fffffff would cause the number to go around to -0x7fffffff (or
    > whatever that is), giving -1 for 0xffffffff?
    >
    > Secondly, (and this is my weak point as a programmer) to re-insert
    > the data after, what would be the most efficient way to pull
    > everything back apart into individual characters for putting it all
    > back into the files? I could probably figure out something that
    > would work, but I wouldn't be so sure as to its reliability.


    I think, from the above, that you want to read about the 'struct'
    module in the standard library.

    <URL:http://docs.python.org/lib/module-struct.html>

    > Third, being a photographer now rather than a coder, I'd like to
    > give back the modules I'm writing to the community (it looks like
    > very little of the sort exists), but would rather not worry about
    > them in the future... Is there a good way to go about this?


    Ideally, find someone who will actively maintain the code into the
    foreseeable future; maybe a user of the code with more interest in
    programming than you.

    Failing that, find a place to put it online for the foreseeable
    future, and notify repositories like Freshmeat
    <URL:http://freshmeat.net/> of its existence and location.

    The most important thing to do is to explicitly license the rights to
    modify and redistribute freely for all people who receive the code, so
    they never have to try to track you down for permission.

    Choose a permissive license like the Expat license
    <URL:http://www.jclark.com/xml/copying.txt> if you want to allow
    people to do just about anything except claim you didn't write it;
    choose a copyleft like the GNU General Public License
    <URL:http://www.gnu.org/copyleft/gpl.html> if you want to ensure
    nobody can redistribute under more restrictive terms in future.

    Make each file clearly marked so that the grant of license is clear,
    and include the text of the license terms in an obvious file in the
    source code package. See the addendum of the GNU GPL for how this is
    best done, even if you end up not choosing that particular license.

    Thanks for thinking of the future hackers :)

    --
    \ "...one of the main causes of the fall of the Roman Empire was |
    `\ that, lacking zero, they had no way to indicate successful |
    _o__) termination of their C programs." -- Robert Firth |
    Ben Finney
     
    Ben Finney, Dec 20, 2006
    #1
    1. Advertising

  2. Ben Finney

    John Machin Guest

    Fall of Roman Empire

    Ben Finney wrote:

    > \ "...one of the main causes of the fall of the Roman Empire was |
    > `\ that, lacking zero, they had no way to indicate successful |
    > _o__) termination of their C programs." -- Robert Firth |



    An amusing .sig, but it doesn't address the root cause: As they had no
    way of testing for the end of a string, in many cases successful
    termination of their C programs would have been unlikely.

    Cheers,
    John
     
    John Machin, Dec 20, 2006
    #2
    1. Advertising

  3. Ben Finney

    Ben Finney Guest

    Re: Fall of Roman Empire

    "John Machin" <> writes:

    > Ben Finney wrote:
    >
    > > \ "...one of the main causes of the fall of the Roman Empire was |
    > > `\ that, lacking zero, they had no way to indicate successful |
    > > _o__) termination of their C programs." -- Robert Firth |

    >
    > An amusing .sig, but it doesn't address the root cause: As they had no
    > way of testing for the end of a string, in many cases successful
    > termination of their C programs would have been unlikely.


    Yet historically proven: the 'imperium' process they were running
    terminated many centuries ago.

    Or did it fork and exec a different process?

    --
    \ "I wish there was a knob on the TV to turn up the intelligence. |
    `\ There's a knob called 'brightness' but it doesn't work." -- |
    _o__) Eugene P. Gallagher |
    Ben Finney
     
    Ben Finney, Dec 20, 2006
    #3
  4. Ben Finney

    Thomas Ploch Guest

    Re: Fall of Roman Empire

    Ben Finney schrieb:
    > "John Machin" <> writes:
    >
    >> Ben Finney wrote:
    >>
    >>> \ "...one of the main causes of the fall of the Roman Empire was |
    >>> `\ that, lacking zero, they had no way to indicate successful |
    >>> _o__) termination of their C programs." -- Robert Firth |

    >> An amusing .sig, but it doesn't address the root cause: As they had no
    >> way of testing for the end of a string, in many cases successful
    >> termination of their C programs would have been unlikely.

    >
    > Yet historically proven: the 'imperium' process they were running
    > terminated many centuries ago.
    >
    > Or did it fork and exec a different process?
    >


    And what about the C-Programs running in the middle of the sun or earth
    making them spinning around or having nuclear reactions controlled. I
    hope they won't terminate in the near future with exit status != 0
     
    Thomas Ploch, Dec 20, 2006
    #4
  5. Ben Finney

    Chris Mellon Guest

    Re: Fall of Roman Empire

    On 12/20/06, Ben Finney <> wrote:
    > "John Machin" <> writes:
    >
    > > Ben Finney wrote:
    > >
    > > > \ "...one of the main causes of the fall of the Roman Empire was |
    > > > `\ that, lacking zero, they had no way to indicate successful |
    > > > _o__) termination of their C programs." -- Robert Firth |

    > >
    > > An amusing .sig, but it doesn't address the root cause: As they had no
    > > way of testing for the end of a string, in many cases successful
    > > termination of their C programs would have been unlikely.

    >
    > Yet historically proven: the 'imperium' process they were running
    > terminated many centuries ago.
    >
    > Or did it fork and exec a different process?
    >


    According to the C standard (16AD version), access past the end of an
    imperial era results in undefined behavior.
     
    Chris Mellon, Dec 20, 2006
    #5
  6. Ben Finney

    Thomas Ploch Guest

    Re: Fall of Roman Empire

    > Ben Finney schrieb:
    >> "John Machin" <> writes:
    >>
    >>> Ben Finney wrote:
    >>>
    >>>> \ "...one of the main causes of the fall of the Roman Empire was |
    >>>> `\ that, lacking zero, they had no way to indicate successful |
    >>>> _o__) termination of their C programs." -- Robert Firth |
    >>> An amusing .sig, but it doesn't address the root cause: As they had no
    >>> way of testing for the end of a string, in many cases successful
    >>> termination of their C programs would have been unlikely.

    >> Yet historically proven: the 'imperium' process they were running
    >> terminated many centuries ago.
    >>
    >> Or did it fork and exec a different process?
    >>


    I rather stay with the metaphysics:


    #include "metaphysics.h"

    static metaPower God;

    universe *makeUniverse(metaPower God)
    {
    if (!God) {
    printf("Oops, no God available at the moment.Try again later!");
    return NULL;
    }

    universe *everything;

    if (!(everything = malloc(sizeof(universe)))) {
    God.mood = REALLY_BORED;
    printf("God has no time to create a universe.");
    return NULL;
    } else {
    return universe;
    }
    }


    :)

    Sorry, somehow had to do this. Please slap me (i like it, don't worry)
    if it's totally stupid
     
    Thomas Ploch, Dec 20, 2006
    #6
  7. Ben Finney

    Felix Benner Guest

    Re: Fall of Roman Empire

    Thomas Ploch schrieb:
    >> Ben Finney schrieb:
    >>> "John Machin" <> writes:
    >>>
    >>>> Ben Finney wrote:
    >>>>
    >>>>> \ "...one of the main causes of the fall of the Roman Empire was |
    >>>>> `\ that, lacking zero, they had no way to indicate successful |
    >>>>> _o__) termination of their C programs." -- Robert Firth |
    >>>> An amusing .sig, but it doesn't address the root cause: As they had no
    >>>> way of testing for the end of a string, in many cases successful
    >>>> termination of their C programs would have been unlikely.
    >>> Yet historically proven: the 'imperium' process they were running
    >>> terminated many centuries ago.
    >>>
    >>> Or did it fork and exec a different process?
    >>>

    >
    > I rather stay with the metaphysics:
    >
    >
    > #include "metaphysics.h"
    >
    > static metaPower God;
    >
    > universe *makeUniverse(metaPower God)
    > {
    > if (!God) {
    > printf("Oops, no God available at the moment.Try again later!");
    > return NULL;
    > }
    >
    > universe *everything;
    >
    > if (!(everything = malloc(sizeof(universe)))) {
    > God.mood = REALLY_BORED;
    > printf("God has no time to create a universe.");
    > return NULL;
    > } else {
    > return universe;
    > }
    > }
    >
    >
    > :)
    >
    > Sorry, somehow had to do this. Please slap me (i like it, don't worry)
    > if it's totally stupid
    >
    >


    soooo totally stupid! You forgot the main function! (not to mention you
    returned universe instead of everything)

    static int main(int argc, char **argv) {
    char *god_name;
    if (argc)
    god_name = argv[1];
    else
    god_name = "YHWH";
    metaPower God = getGodByName(god_name);
    universe *everything = makeUniverse(God);
    while (simulatePhysics(everything));
    return 0;
    }
     
    Felix Benner, Dec 20, 2006
    #7
  8. Ben Finney

    Thomas Ploch Guest

    Re: Fall of Roman Empire

    Felix Benner schrieb:
    > Thomas Ploch schrieb:
    >>> Ben Finney schrieb:
    >>>> "John Machin" <> writes:
    >>>>
    >>>>> Ben Finney wrote:
    >>>>>
    >>>>>> \ "...one of the main causes of the fall of the Roman Empire was |
    >>>>>> `\ that, lacking zero, they had no way to indicate successful |
    >>>>>> _o__) termination of their C programs." -- Robert Firth |
    >>>>> An amusing .sig, but it doesn't address the root cause: As they had no
    >>>>> way of testing for the end of a string, in many cases successful
    >>>>> termination of their C programs would have been unlikely.
    >>>> Yet historically proven: the 'imperium' process they were running
    >>>> terminated many centuries ago.
    >>>>
    >>>> Or did it fork and exec a different process?
    >>>>

    >> I rather stay with the metaphysics:
    >>
    >>
    >> #include "metaphysics.h"
    >>
    >> static metaPower God;
    >>
    >> universe *makeUniverse(metaPower God)
    >> {
    >> if (!God) {
    >> printf("Oops, no God available at the moment.Try again later!");
    >> return NULL;
    >> }
    >>
    >> universe *everything;
    >>
    >> if (!(everything = malloc(sizeof(universe)))) {
    >> God.mood = REALLY_BORED;
    >> printf("God has no time to create a universe.");
    >> return NULL;
    >> } else {
    >> return universe;
    >> }
    >> }
    >>
    >>
    >> :)
    >>
    >> Sorry, somehow had to do this. Please slap me (i like it, don't worry)
    >> if it's totally stupid
    >>
    >>

    >
    > soooo totally stupid! You forgot the main function! (not to mention you
    > returned universe instead of everything)


    Argh, I need some serious slapping (but I changed everything and
    universe, and just forgot to change it all the way through (...good that
    I am _not_ God)

    > static int main(int argc, char **argv) {
    > char *god_name;
    > if (argc)
    > god_name = argv[1];
    > else
    > god_name = "YHWH";
    > metaPower God = getGodByName(god_name);
    > universe *everything = makeUniverse(God);
    > while (simulatePhysics(everything));
    > return 0;
    > }


    You forgot to check if God wasn't too bored. ;-)

    Thomas
     
    Thomas Ploch, Dec 20, 2006
    #8
  9. Ben Finney

    Georg Brandl Guest

    Re: Fall of Roman Empire

    Felix Benner schrieb:

    >> Sorry, somehow had to do this. Please slap me (i like it, don't worry)
    >> if it's totally stupid
    >>
    >>

    >
    > soooo totally stupid! You forgot the main function! (not to mention you
    > returned universe instead of everything)
    >
    > static int main(int argc, char **argv) {
    > char *god_name;
    > if (argc)
    > god_name = argv[1];
    > else
    > god_name = "YHWH";
    > metaPower God = getGodByName(god_name);
    > universe *everything = makeUniverse(God);
    > while (simulatePhysics(everything));
    > return 0;
    > }


    Well, I'd expect God to be more clever as to do it that way.
    Could you imagine toying around with your universe in C?

    No, it must have been

    static PyObject *
    create_universe(char *god_name) {
    PyObject *universe;
    universe = PyObject_New(universetype, PyUniverse_Type);
    if (!universe) {
    PyErr_SetString(PyExc_CreationError,
    "Out of spacetime, or BDFL is too busy hacking "
    "on web-based collaboration tools");
    return NULL;
    }
    universe->un_god = PyGod_FromName(god_name);
    universe->un_size = 0;
    universe->un_expand_rate = COSMOLOGICAL_CONSTANT;
    return universe;
    }

    Georg
     
    Georg Brandl, Dec 20, 2006
    #9
  10. Re: Fall of Roman Empire

    Ben Finney <> wrote:
    >"John Machin" <> writes:
    >> Ben Finney wrote:
    >> > \ "...one of the main causes of the fall of the Roman Empire was |
    >> > `\ that, lacking zero, they had no way to indicate successful |
    >> > _o__) termination of their C programs." -- Robert Firth |

    >> [ ... ] in many cases successful
    >> termination of their C programs would have been unlikely.

    >Yet historically proven: the 'imperium' process they were running
    >terminated many centuries ago.
    >
    >Or did it fork and exec a different process?


    Pretty much. Except they would argue that the child process
    (Byzantium) never exec'd.

    --
    \S -- -- http://www.chaos.org.uk/~sion/
    ___ | "Frankly I have no feelings towards penguins one way or the other"
    \X/ | -- Arthur C. Clarke
    her nu becomeþ se bera eadward ofdun hlæddre heafdes bæce bump bump bump
     
    Sion Arrowsmith, Dec 20, 2006
    #10
  11. Re: Fall of Roman Empire

    "Thomas Ploch" <> wrote:


    > Ben Finney schrieb:
    > > "John Machin" <> writes:
    > >
    > >> Ben Finney wrote:
    > >>
    > >>> \ "...one of the main causes of the fall of the Roman Empire was |
    > >>> `\ that, lacking zero, they had no way to indicate successful |
    > >>> _o__) termination of their C programs." -- Robert Firth |
    > >> An amusing .sig, but it doesn't address the root cause: As they had no
    > >> way of testing for the end of a string, in many cases successful
    > >> termination of their C programs would have been unlikely.

    > >
    > > Yet historically proven: the 'imperium' process they were running
    > > terminated many centuries ago.
    > >
    > > Or did it fork and exec a different process?
    > >

    >
    > And what about the C-Programs running in the middle of the sun or earth
    > making them spinning around or having nuclear reactions controlled. I
    > hope they won't terminate in the near future with exit status != 0


    naaah - you don't have to worry - for real control He uses assembler.
    with jump statements.
    so the loops are closed.

    Unfortunately its not open source. Yet.

    - Hendrik
     
    Hendrik van Rooyen, Dec 21, 2006
    #11
  12. Ben Finney

    Dan Bishop Guest

    Re: Fall of Roman Empire

    Dec 20, 10:36 am, Felix Benner <> wrote:

    > static int main(int argc, char **argv) {
    > char *god_name;
    > if (argc)
    > god_name = argv[1];
    > else
    > god_name = "YHWH";
    > metaPower God = getGodByName(god_name);
    > universe *everything = makeUniverse(God);
    > while (simulatePhysics(everything));
    > return 0;
    > }


    This won't work if there are no command-line arguments. You mean if
    (argc > 1).
     
    Dan Bishop, Dec 24, 2006
    #12
    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. Jason Heyes
    Replies:
    2
    Views:
    593
    Jason Heyes
    Feb 14, 2005
  2. Guest
    Replies:
    0
    Views:
    367
    Guest
    Dec 20, 2006
  3. Guest
    Replies:
    1
    Views:
    348
  4. Sriniv

    Unsigned and signed char types

    Sriniv, Jun 12, 2005, in forum: C Programming
    Replies:
    4
    Views:
    293
    William Ahern
    Jun 13, 2005
  5. pozz
    Replies:
    12
    Views:
    749
    Tim Rentsch
    Mar 20, 2011
Loading...

Share This Page