LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 09-27-2005, 02:23 PM   #1
exvor
Senior Member
 
Registered: Jul 2004
Location: Phoenix, Arizona
Distribution: LFS-Version SVN-20091202, Arch 2009.08
Posts: 1,485

Rep: Reputation: 66
C Enum


Code:
 
#include<stdio.h>

int main()

{
  int east = 5;
  enum direction {
         north,
         south,
         west
       };
   enum direction points;
     points = east;

     if (points == north)
        printf("The direction is north\n");
     else
       printf("The direction is not north\n");
    return 0;
}

In an effort not to hijack another thread i created this one for a little
help understanding enum


now according to what im told/read this code should generate an error
when compiling because im assigning it something thats not enum'ed
at least a warning. This is not so. Gcc gives no error or warning not even
with -Wall


so is this a leagal use of enum or should i be getting a warning ?
 
Old 09-27-2005, 02:41 PM   #2
kjordan
Member
 
Registered: Jul 2004
Distribution: LFS, I felt the itch and scratched it
Posts: 227

Rep: Reputation: 31
Yes, that's legal. If you define something with an enum type, the compiler makes it an integer so you can have any value assigned to it, not just those in your enum statement.
 
Old 09-27-2005, 02:44 PM   #3
exvor
Senior Member
 
Registered: Jul 2004
Location: Phoenix, Arizona
Distribution: LFS-Version SVN-20091202, Arch 2009.08
Posts: 1,485

Original Poster
Rep: Reputation: 66
then whats the point in using it ? why not just declare regular varibles.
 
Old 09-27-2005, 02:51 PM   #4
kjordan
Member
 
Registered: Jul 2004
Distribution: LFS, I felt the itch and scratched it
Posts: 227

Rep: Reputation: 31
The advantage of an enum is that it has scope, compared to a #define statement. You could just use regular variables, but that advantage to this is it automatically numbers them for you so you don't have to go through the process of doing that.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
HOTSWAP: where to find #ENUM signal? iflorea Programming 0 11-20-2005 06:58 AM
C, enum confusion cigarstub Programming 2 09-27-2005 09:59 AM


All times are GMT -5. The time now is 04:42 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration