Thread: Why the simple code doesn't compile?

  1. #1
    Registered User
    Join Date
    Apr 2007

    Why the simple code doesn't compile?

    Here is the code:
    #include <stdio.h>
    extern end;
    extern edata;
    extern etext;
    int I;
    main(int argc, char **argv)
      int i;
      int *ii;
      printf("&etext = 0x%lx\n", &etext);
      printf("&edata = 0x%lx\n", &edata);
      printf("&end   = 0x%lx\n", &end);
      ii = (int *) malloc(sizeof(int));
      printf("main   = 0x%lx\n", main);
      printf("&I     = 0x%lx\n", &I);
      printf("&i     = 0x%lx\n", &i);
      printf("&argc  = 0x%lx\n", &argc);
      printf("&ii    = 0x%lx\n", &ii);
      printf("ii     = 0x%lx\n", ii);
    But the compiler complains:
    g++ -c -g -o main.o error: ISO C++ forbids declaration of `end' with no type error: ISO C++ forbids declaration of `edata' with no type error: ISO C++ forbids declaration of `etext' with no type

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    "extern" is not a data type. You need "extern int" or "extern void*" or whatever.

  3. #3
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    United States
    In fact I don't see why you need extern at all.

  4. #4
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Indeed, you'll just get linker errors that way.

    Also, are you aware that you're writing C code but posting in the C++ board?
    All the buzzt!

    "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

  5. #5
    Join Date
    Oct 2007
    Inside my computer
    It's compiled using C++, though, so main must return int or you'll get another error.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compile Errors in my Code. Can anyone help?
    By DGLaurynP in forum C Programming
    Replies: 1
    Last Post: 10-06-2008, 09:36 AM
  2. Code will not compile - code from a book!
    By Chubz in forum C++ Programming
    Replies: 19
    Last Post: 09-12-2004, 10:21 PM
  3. True ASM vs. Fake ASM ????
    By DavidP in forum A Brief History of
    Replies: 7
    Last Post: 04-02-2003, 04:28 AM
  4. Replies: 1
    Last Post: 01-29-2002, 02:49 AM
  5. Simple Compile Time Problem - HELP!
    By kamikazeecows in forum Windows Programming
    Replies: 2
    Last Post: 12-02-2001, 01:30 PM