Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Novice with Linux C question 3

Status
Not open for further replies.

Bosah

MIS
Feb 9, 2001
39
0
0
CA
When I compile this in gcc I get

"warning: null character(s) ignored" for line 8,18,20,22,30,34

and "missing terminating " character" for line 34

and lastly "relay.c:4:508: warning: no newline at end of file"

With apologies for what I don't know, can anyone help me :)


Code:
source:


  /*
  * relay.c: very simple port I/O
  *
  * Compile with `gcc -O2 -o relay relay.c',
  * and run as root with `./relay'.
  * This program reads from standard in until it gets a EOF (^D)
  * to use in unattended mode just run as relay < inputfile
  */

  #include <stdio.h>
  #include <unistd.h>
  #include <asm/io.h>

  #define BASEPORT 0x3FC /*com 1 */
  define BASEPORT 0x2FC /*com 2 */

  int main()
  {
  int a;
  int x;
  /* Get access to the ports */
  if (ioperm(BASEPORT, 1, 1)) {
     fprintf(stderr,&quot;error performing ioperm\n&quot;);
     exit(1);
  }

  do {
     a=fgetc(stdin);
     if (a == EOF)  continue; // Jump to end of loop on end condition
     x = inb(BASEPORT);
     if (a == 49) x &= ~2; // If you get a 0 in clear relay #1
     if (a == 50) x |= 2; // If you get a 1 in set relay #1
     if (a == 51) x &= ~1; // If you get a 2 in clear relay #2
     if (a == 52) x |= 1; // If you get a 3 in set relay #3
     outb(x, BASEPORT);
     usleep(100); // Wait 100 microseconds.
  } while (a != EOF);
     /* We don't need the ports anymore */
  if (ioperm(BASEPORT, 1, 0)) {
     fprintf(stderr,&quot;error closing ioperm\n&quot;);
     exit(1);
  }

  exit(0);
  }
 
I do not have gcc but I can see one problem.. And this may solve all others error :)

You write:
#define BASEPORT 0x3FC /*com 1 */
define BASEPORT 0x2FC /*com 2 */ // <- Miss a '#'

Correction
#define BASEPORT 0x3FC /*com 1 */
#define BASEPORT 0x2FC /*com 2 */

 
OOps :(
I also don't think that the pre-compiler will love the
#define BASEPORT 0x3FC /*com 1 */
#define BASEPORT 0x2FC /*com 2 */

Both BASEPORT definition may be not allowed.
Try to use 2 different name like BASEPORT_COM_1 and _COM_2.
 
I thought the &quot;#&quot; sign was a comment so I added the second baseport and removed the &quot;#&quot; to activate it. Oops
 
I have not used the inb and outb fucntions in Unix but the I can some error in this program.

1. the # in the BASEPORT 0x2F8 and both the macros are having the same name, it not allowed
2. in the comment after the baseport.

#define BASEPORT 0x3FC /*com 1 */
#define BASEPORT 0x2FC /*com 2 */

comments are not allowed in the macro definition, it means
all the BASEPORT in the program will be replace by 0x3FC /* com 1*/.

for example the x = inb(BASEPORT); will be changed to x = inb(0x3FC /* com 1*/); and it will cause errors.

I hope this may useful for you

Regards
Maniraja S



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top