Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Python (http://www.velocityreviews.com/forums/f43-python.html)
-   -   Re: Working with unsigned/signed types (http://www.velocityreviews.com/forums/t397527-re-working-with-unsigned-signed-types.html)

Ben Finney 12-20-2006 06:07 AM

Re: Working with unsigned/signed types
 
<brian@brianshirk.com> 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


John Machin 12-20-2006 06:24 AM

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


Ben Finney 12-20-2006 06:56 AM

Re: Fall of Roman Empire
 
"John Machin" <sjmachin@lexicon.net> 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


Thomas Ploch 12-20-2006 12:32 PM

Re: Fall of Roman Empire
 
Ben Finney schrieb:
> "John Machin" <sjmachin@lexicon.net> 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

Chris Mellon 12-20-2006 02:51 PM

Re: Fall of Roman Empire
 
On 12/20/06, Ben Finney <bignose+hates-spam@benfinney.id.au> wrote:
> "John Machin" <sjmachin@lexicon.net> 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.

Thomas Ploch 12-20-2006 04:27 PM

Re: Fall of Roman Empire
 
> Ben Finney schrieb:
>> "John Machin" <sjmachin@lexicon.net> 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



Felix Benner 12-20-2006 04:36 PM

Re: Fall of Roman Empire
 
Thomas Ploch schrieb:
>> Ben Finney schrieb:
>>> "John Machin" <sjmachin@lexicon.net> 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;
}

Thomas Ploch 12-20-2006 04:52 PM

Re: Fall of Roman Empire
 
Felix Benner schrieb:
> Thomas Ploch schrieb:
>>> Ben Finney schrieb:
>>>> "John Machin" <sjmachin@lexicon.net> 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

Georg Brandl 12-20-2006 05:15 PM

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

Sion Arrowsmith 12-20-2006 05:26 PM

Re: Fall of Roman Empire
 
Ben Finney <bignose+hates-spam@benfinney.id.au> wrote:
>"John Machin" <sjmachin@lexicon.net> 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 -- siona@chiark.greenend.org.uk -- 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


All times are GMT. The time now is 02:40 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.