Sponsored Content
Full Discussion: enumeration types in C
Top Forums Programming enumeration types in C Post 302224138 by cleopard on Tuesday 12th of August 2008 09:25:07 AM
Old 08-12-2008
enumeration types in C

If I want to declare an array of structures in C and have the number of items in that array to correspond to the items of an enumeration, is there a way to access the maximum value in the enumeration when declaring the array?

For instance:

typedef struct
{
various fields....
} fruit_rec;

enum fruit_info {apple, orange, banana}

fruit_rec fruits[3];


Instead of hard-coding a '3' in the 'fruits' declaration, is there a way I can access the number of items in the enumeration? In the old DoD language, Ada, one could do something like, " fruit_rec fruits[fruit_info] " .

I don't think there is a way to do what I'm asking, but I thought I'd ask as it would be a cleaner way of declaring things. Even if I can't do something like that, I know I can still refer to the elements as "fruits[apple}" , "fruits[orange]", etc. Thank you.
 

8 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

servers types

dear sir , i would like to ask about sun solaries servers generations ? i hear about sparc and ultra . i want to know the versions , and is there other servers types ?? Thank (3 Replies)
Discussion started by: tamemi
3 Replies

2. UNIX for Dummies Questions & Answers

So many types of LINUX's!

I installed Redhat into my system. The reason? This was the version my friend was running and he told me about this one, so I downloaded and installed it. Simple enough :D But as I am searching the net, I am coming across many other forms of linux made by other companies. Redhat seems to be... (2 Replies)
Discussion started by: Minnesota Red
2 Replies

3. Programming

X-Windows Enumeration

Hi, I'm new to x-windows system and I have a few questions: 1. How can I write a C program to enumerate all the windows on the local and remote computers? In other words: How can I create a list of all the windows in the system (maximized/minimized/active/not active ....)? 2. How can I... (0 Replies)
Discussion started by: itaihoe
0 Replies

4. UNIX for Dummies Questions & Answers

Two types of pipes?

What is the difference between: cd /tmp tar -cf - *.txt |gzip > tmp_txt.tar.gz and cd /tmp mknod pipe p gzip < pipe > /tmp/tmp_txt1.tar.gz & tar -cf pipe *.txt Apart from the fact that we have to create the pipe file manually, is there any difference in the performance of the two?... (5 Replies)
Discussion started by: blowtorch
5 Replies

5. UNIX for Dummies Questions & Answers

mime types

Hi, I am trying to launch an ogg movie from a pdf file which has been produced with pdflatex and \movie {\centerline{\includegraphics {grafiques_xerrades/un_manolo_amb_camera.pdf}}} {hlims_xerrades/XocCumuls.ogg} The switch "externalviewer" makes kpdf launch the default... (5 Replies)
Discussion started by: pau
5 Replies

6. UNIX for Dummies Questions & Answers

Un-compression types...

Hi Folks, As I am familiar wih both types compresion forms: gun-zip and .rpm. My questions is how do I uncompress gunz.zip type? As the .rpm I can double click and it will extract...Can someone shed some light on this and thank you... M (2 Replies)
Discussion started by: Mombo_Z
2 Replies

7. What is on Your Mind?

What Types of Food Do You Like The Most?

On another simple topic, multiple choice answers OK ( you can pick more than one or suggest others - we will add your suggestions to the poll ). What Types of Food Do You Like The Most? (27 Replies)
Discussion started by: Neo
27 Replies

8. Shell Programming and Scripting

Cp -r except certain file types

the following excludes certain directories successfully cp -r probe/!(dir) /destination I want to exclude certain file types and tried unsuccessfully cp -r probe/!(*.avi) /destination (2 Replies)
Discussion started by: tmf
2 Replies
Alt-Ergo(1)						      General Commands Manual						       Alt-Ergo(1)

NAME
Alt-Ergo - An automatic theorem prover dedicated to program verification SYNOPSIS
alt-ergo [ options ] files DESCRIPTION
Alt-Ergo is an automatic theorem prover. It takes as inputs an arbitrary polymorphic and multi-sorted first-order formula written is the Why's syntax. OPTIONS
-h Help. Will give you the full list of command line options. A theory of functional arrays with integer indexes . This theory provides a built-in type ('a,'b) farray and a built-in syntax for manipulating arrays. For instance, given an abstract datatype tau and a functional array t of type (int, tau) farray declared as follows: type tau logic t : (int, tau) farray The expressions: t[i] denotes the value stored in t at index i t[i1<-v1,...,in<-vn] denotes an array which stores the same values as t for every index except possibly i1,...,in, where it stores value v1,...,vn. This expression is equivalent to ((t[i1<-v1])[i2<-v2])...[in<-vn]. Examples. t[0<-v][1<-w] t[0<-v, 1<-w] t[0<-v, 1<-w][1] A theory of enumeration types. For instance an enumeration type t with constructors A, B, C is defined as follows : type t = A | B | C Which means that all values of type t are equal to either A, B or C. And that all these constructors are distinct. A theory of polymorphic records. For instance a polymorphic record type 'a t with two labels a and b of type 'a and int respectively is defined as follows: type 'a t = { a : 'a; b : int } The expressions { a = 4; b = 5 } and { r with b = 3} denote records, while the dot notation r.a is used to access to labels. ENVIRONMENT VARIABLES
ERGOLIB Alternative path for the Alt-Ergo library AUTHORS
Sylvain Conchon <conchon@lri.fr> and Evelyne Contejean <contejea@lri.fr> SEE ALSO
Alt-Ergo web site: http://alt-ergo.lri.fr October, 2006 Alt-Ergo(1)
All times are GMT -4. The time now is 08:51 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy