Find the answer to your Linux question:
Results 1 to 8 of 8
I know - Minix is outdated, but it's for a school project. Attached is my code for the open() command. On compiling, I keep running into the error: "open.c", Line ...
  1. #1
    Just Joined!
    Join Date
    Dec 2006
    Posts
    41

    [SOLVED] cc compiler error with char* in Minix

    I know - Minix is outdated, but it's for a school project.

    Attached is my code for the open() command. On compiling, I keep running into the error:

    "open.c", Line 65: . not expected

    How helpful. "." Not expected. I have tried multiple ways of declaring this string:

    Code:
    char* pathname = (char*)malloc(100);
    char* pathname = malloc(100);
    char* pathname = (char*)malloc(100 * sizeof * pathname);
    char* pathname = (char*)malloc(100 * sizeof *char);
    The list continues. I thought maybe I forgot a header, but I don't see what could be missing. Any thoughts? Thanks bunches in advance!
    Attached Files Attached Files

  2. #2
    Linux Enthusiast gerard4143's Avatar
    Join Date
    Dec 2007
    Location
    Canada, Prince Edward Island
    Posts
    714
    Are you sure that line number 65 in your error message refers to

    Code:
    char* pathname = (char*)malloc(100);
    Make mine Arch Linux

  3. #3
    Just Joined!
    Join Date
    Dec 2006
    Posts
    41
    Very sure. I just double checked. I've had problems getting malloc() syntax right in gcc before, but the Minix cc is really picky. Any thoughts? I really appreciate it.

  4. #4
    Linux Enthusiast gerard4143's Avatar
    Join Date
    Dec 2007
    Location
    Canada, Prince Edward Island
    Posts
    714
    Well your compiler is having problems with a "." on line 65. Line 65 doesn't have a period so maybe the compiler is a little confused as to where the syntax violation is and this is its best guess...Gerard4143
    Make mine Arch Linux

  5. #5
    Just Joined!
    Join Date
    Dec 2006
    Posts
    41
    Okay, I figured it out, but it doesn't make sense, and I don't understand WHY it was an error. I understand that pathname is both a member of min and a char*. However, simply changing the line to char* path made it work. May Minix die a slow death . . .

  6. #6
    Linux Enthusiast gerard4143's Avatar
    Join Date
    Dec 2007
    Location
    Canada, Prince Edward Island
    Posts
    714
    Are you saying the compiler expected a "." for the variable pathname because it was also declared as a member of the m_in structure? That is weird...Gerard4143
    Make mine Arch Linux

  7. #7
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
    Posts
    8,974
    Quote Originally Posted by summersab View Post
    I know - Minix is outdated, but it's for a school project.

    Attached is my code for the open() command. On compiling, I keep running into the error:

    "open.c", Line 65: . not expected

    How helpful. "." Not expected. I have tried multiple ways of declaring this string:

    Code:
    char* pathname = (char*)malloc(100);
    char* pathname = malloc(100);
    char* pathname = (char*)malloc(100 * sizeof * pathname);
    char* pathname = (char*)malloc(100 * sizeof *char);
    The list continues. I thought maybe I forgot a header, but I don't see what could be missing. Any thoughts? Thanks bunches in advance!
    What are you trying to do? The last 3 allocations are bogus. First off, on the 2nd example, malloc() returns a void*, not a char*, so this will fail if you are compiling with ANSI compliance or for C++. The 3rd and 4th examples are multiplying either the address of sizeof() on systems where it is a function, or may generate a compiler error where sizeof is a macro. In either case, these are invalid constructs.

    So, my guess is that you are trying to compile Minix code with a current GNU C compiler in Linux, correct? That's why you are getting errors. You need to correct the code first.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  8. #8
    Just Joined!
    Join Date
    Dec 2006
    Posts
    41
    Rubberman (awkward name, btw) - I got it to work by changing pathname to path. That worked for some reason. Thanks, anyway!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...