[Courses] Re: [C] My Life program...
Cynthia Grossen
cgrossen at lans.mha.org
Fri Jul 26 10:49:31 EST 2002
array[bit/8] &= ~(1<<(bit%8));
This line strikes me as really intense. It seems like there's so much going
on here.
My interpretation of the line is:
Do a bitwise AND on the array at position bit/8 with the bitwise complement
of 1 left-shifted bit%8 positions.
Is this a correct interpretation?
printf("Error: You must give all 62 characters. Only x's and .'s please."
"\x1b[1A\x1b[1G");
Also on this line, the arguments given for printf "\x1b[1A\x1b[1G" what do
they mean?
I should say that I am doing this at work and b/c of this I am using M$ C++
environment, my docs indicate that the argument for the printf function is
used for format strings, and that a format string always begins with %, so I
am thinking that this is not a format string. They do have an third
parameter for optional arguments, which is what this is presumably.
printf("\x1b[H\x1b[2J");
This line seems to explain things a little bit, plus the comments on lines
around help. This is looks like its used for printing out the lines
indicating the petri dish. But I'd still like to know what it all means. And
if that's correct.
And one last thing, when I compile this prg I get several errors, presumably
b/c suzi's environment is dif. than mine. Is there anything that I can do
about this? IOW, are the compile errors b/c I'm using M$ C++ and suzi's
using somebody else's product? Or are there compiler arguments that I need
to pass. Or is it something completely different?
Here are the compilation errors that I received.
-------------------Configuration: life1-1 - Win32 Debug--------------------
Compiling...
life1-1.c
c:\program files\microsoft visual studio\vc98\include\stdint.h(14) : error
C2632: 'long' followed by 'long' is illegal
c:\program files\microsoft visual studio\vc98\include\stdint.h(20) : error
C2632: 'long' followed by 'long' is illegal
C:\work\misc programs\Suzi's Game of Life\life1-1.c(31) : error C2054:
expected '(' to follow 'inline'
C:\work\misc programs\Suzi's Game of Life\life1-1.c(32) : error C2085:
'set_bit' : not in formal parameter list
C:\work\misc programs\Suzi's Game of Life\life1-1.c(32) : error C2143:
syntax error : missing ';' before '{'
C:\work\misc programs\Suzi's Game of Life\life1-1.c(36) : error C2054:
expected '(' to follow 'inline'
C:\work\misc programs\Suzi's Game of Life\life1-1.c(37) : error C2085:
'clr_bit' : not in formal parameter list
C:\work\misc programs\Suzi's Game of Life\life1-1.c(37) : error C2143:
syntax error : missing ';' before '{'
C:\work\misc programs\Suzi's Game of Life\life1-1.c(42) : error C2054:
expected '(' to follow 'inline'
C:\work\misc programs\Suzi's Game of Life\life1-1.c(43) : error C2085:
'test_bit' : not in formal parameter list
C:\work\misc programs\Suzi's Game of Life\life1-1.c(43) : error C2143:
syntax error : missing ';' before '{'
C:\work\misc programs\Suzi's Game of Life\life1-1.c(59) : warning C4013:
'clr_bit' undefined; assuming extern returning int
C:\work\misc programs\Suzi's Game of Life\life1-1.c(64) : warning C4013:
'set_bit' undefined; assuming extern returning int
C:\work\misc programs\Suzi's Game of Life\life1-1.c(93) : warning C4013:
'test_bit' undefined; assuming extern returning int
Error executing cl.exe.
life1-1.obj - 11 error(s), 3 warning(s)
----------------------------------------------------------------------------
-------
/*
* ISO C99: 7.18 Integer types <stdint.h>
*/
#ifndef _STDINT_H
#define _STDINT_H 1
/* Exact integral types. */
/* Signed. */
typedef signed char int8_t;
typedef short int int16_t;
typedef int int32_t;
typedef long long int int64_t;
/* Unsigned. */
typedef unsigned char uint8_t;
typedef unsigned short int uint16_t;
typedef unsigned int uint32_t;
typedef unsigned long long int uint64_t;
#endif /* stdint.h */
----------------------------------------------------------------------------
--------------
Line 31 from the prg -- inline void set_bit (uint8_t array[], unsigned int
bit)
Thank you suzi for posting your code, its really cool.
.cyn.
More information about the Courses
mailing list