Windows vs Linux compilation

This is a discussion on Windows vs Linux compilation within the C Programming forums, part of the General Programming Boards category; Hey im gettin a weird error when i compile this in windows but it compiles fine in linux. strings.c:40: error: ...

  1. #1
    Registered User
    Join Date
    Sep 2005
    Posts
    8

    Windows vs Linux compilation

    Hey im gettin a weird error when i compile this in windows but it compiles fine in linux.

    strings.c:40: error: invalid conversion from `void*' to `char*'

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    
    #define STRING_LEN 80
    #define ARRAY_LEN 10000
    
    void *emalloc(size_t s) {
      void *result = malloc(s);
      if (NULL == result) {
        fprintf(stderr, "Memory allocation failed!\n");
        exit(EXIT_FAILURE);
      }
      return result;
    }
    
    void is(char **a, int n) {
      char *word;
      int j, i, x;
      for (i=0; i<n; i++) {
        word = a[i];
        j = i-1;
        x = strcmp(word, a[i]);
        while (i>=0 && x<0) {
          a[j+1] = a[i];
          j--;
        }
        a[i+1] = word;
      }
    }
    
    int main(void) {
      char word[STRING_LEN];
      char *wordlist[ARRAY_LEN];
      int num_words;
      int i;
    
      num_words = 0;
      while (num_words < ARRAY_LEN && 1 == scanf("%s", word)) {
        wordlist[num_words] = emalloc((strlen(word) + 1) * sizeof wordlist[0][0]); /*THIS LINE*/
        strcpy(wordlist[num_words], word);
        num_words++;
      }
    
      is(wordlist, num_words);
    
      for(i = 0; i < num_words; i++) {
        printf("%s\n", wordlist[i]);
      }
    
      for(i = 0; i < num_words; i++) {
        free(wordlist[i]);
      }
    
      return EXIT_SUCCESS;
    }
    the algorithm im using for the search isnt correct i know that i just need to get it to compile before i can fix it. absolutly no idea why it wont compile

    thanks

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    Quote Originally Posted by Pyrce
    Hey im gettin a weird error when i compile this in windows but it compiles fine in linux.

    strings.c:40: error: invalid conversion from `void*' to `char*'
    Do you mean to say that it compiles fine as C, but has issues when compiled as C++? I note the file extension, but it looks like the classic C++ rather than C error.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  3. #3
    Registered User
    Join Date
    Sep 2005
    Posts
    8
    no. trying to compile it as c program. compiles fine in linux. get this error in windows. using minigw and the codeblocks ide.

  4. #4
    Registered User
    Join Date
    Jun 2004
    Posts
    277
    Is that sizeof usage consistent? In fact what do you want to do with that line? Aren't you multiplying a memmory adress?

  5. #5
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    Quote Originally Posted by Pyrce
    no. trying to compile it as c program. compiles fine in linux. get this error in windows. using minigw and the codeblocks ide.


    g++ or gcc?
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  6. #6
    Registered User
    Join Date
    Sep 2005
    Posts
    8
    gcc.

  7. #7
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    Odd.
    cc:\Dev-Cpp\bin\make.EXE -f "H:\Forum\C\Gnu.mak" CFG=GnuC
    C:/Dev-Cpp/bin/gcc.exe -c -g -Wall -pedantic -o "H:/Forum/C/GnuC/main.o" "../main.c"
    C:/Dev-Cpp/bin/gcc.exe -g -Wall -pedantic -o "H:/Forum/C/GnuC/myapp.exe" H:/Forum/C/GnuC/main.o
    Build successful
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  8. #8
    Registered User
    Join Date
    Sep 2005
    Posts
    8
    hmm ill get dev-cpp n try that

  9. #9
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    Quote Originally Posted by Maragato
    Aren't you multiplying a memmory adress?
    Nope.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  10. #10
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    Quote Originally Posted by Pyrce
    hmm ill get dev-cpp n try that
    That's where my mingw was installed, I don't use the IDE.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  11. #11
    Registered User
    Join Date
    Sep 2005
    Posts
    8
    wierd. compiled find under devcpp? right ill use dev-cpp till it packs a sad on me lol

    thanks guys

  12. #12
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    Can you show the command line Code::Blocks emits, and also the version of the GCC that comes with Code::Blocks? If it's a bug, I'd rather get enough info to report it.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. windows .dll vs. linux .so - global static objects
    By pheres in forum C++ Programming
    Replies: 11
    Last Post: 11-23-2010, 01:29 PM
  2. Script errors - bool unrecognized and struct issues
    By ulillillia in forum Windows Programming
    Replies: 10
    Last Post: 12-18-2006, 04:44 AM
  3. Why can't Windows run Linux binary executables?
    By Kleid-0 in forum Tech Board
    Replies: 30
    Last Post: 12-04-2005, 11:44 PM
  4. Replies: 1
    Last Post: 10-18-2005, 11:20 AM
  5. Linux and Windows Duel Boot
    By The15th in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 04-26-2002, 05:59 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21