Sponsored Content
Top Forums Programming C- trying to code a 'spare array'; 'enum' fauled. Post 302697883 by alex_5161 on Friday 7th of September 2012 02:12:11 PM
Old 09-07-2012
C- trying to code a 'spare array'; 'enum' fauled.

I am trying to implement a spare array in C that would be referenced by regular integers.
Right away: define array for maximum possible index elements completely is not what I trying to get!!!

It should be a construction that would have just 2 elements if I need to have just two indexes, like 2000 and 5, let say.

(Genarally, as a hash in perl, for example)
If I need to have that indexed by strings or characters, the 'enum' allows to nicely prepare that.

But with integers it is not compiled.
I mean no way to define
Code:
  enum E_TYPE {1,4,2};

By usage my intention is to have a way to work with an array of numbers referencing to elements by another set of numbers, that could be not consecuensed, not from 0 and without using the search by any way (loop, or any other smartness)

So, I would have related info-array, say, like this:
Code:
struct {int key; int val;} Inf_Arr[] = {
   {25, 44},
   {35, 55},
   (1,  99} };

And I would like to get Int_Arr[n].val by some Ref_Arr[ Int_Arr[n].key ]

So, having int a = Ref_Arr[25]; - I would have a==44

One again, I would like to construct data in a way to be able access the 'val' by the 'key' and (!!) - without using a 'switch-case', if, or any loop for each single 'key' through whole Inf_Arr[]

Does anybody know how it could be done?
Any idea?
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Vfstab on spare disk - HOW ? Mount ?

Hi, guys ! Could someone clarify one thing for me: I start machine from disk0, and want to check the /etc/vfstab on disk1. How do i do it ? Tried to write: cd / mount /dev/dsk/c0t1d0s0 /mnt But if I do cd /mnt, it is empty. I expected to see disk1 there ? Or am I wrong ? How do I... (3 Replies)
Discussion started by: DGoubine
3 Replies

2. Programming

what is the base type of enum

helo i have asked in exam what that what is the base type of enum options are given bewlo (1) long int (2) short int (3) signed int (4) unsigned int can u tell me what is the exact answer from the above option Regards, Amit (1 Reply)
Discussion started by: amitpansuria
1 Replies

3. IP Networking

DNS ENUM RR interpretation

Hi Guys, This is really really urgent. Am looking out for some quick answers. I'm developing a DNS Resolver client that interprets DNS Query repsonses & pass on the needful to DNS applications. When an ENUM query(modified to an nslookup naptr query) is issued & an NAPTR RR(Resource Record)... (1 Reply)
Discussion started by: smanu
1 Replies

4. Programming

enum in c++

#include <iostream> #include <stdio.h> using namespace std; typedef struct A { enum a{ red,blue,green}a; }obj11; obj11 obj1; int main() { //obj1.a=red; // how to set variable ? cout<<"sizeof struct is n"<<sizeof(obj1); cout<<"obj1.a is"<<obj1.a; if... (1 Reply)
Discussion started by: crackthehit007
1 Replies

5. Solaris

Hot Spare pool

One more query in SVM :) Now with hot spare spool... I can understand adding/replacing a slice in particular hot spare pool with "-a / -r" option (or) adding a slice to all existing hot spare pool with "-all" option. Here my query is for deleting, we have only option "-d". 1) If the hot... (2 Replies)
Discussion started by: gowthamakanthan
2 Replies

6. Solaris

Hot Spare replacement

Hi Guys, Can Someone pls let me know the thorough process for Hot spare replacement as current Hot spare slice has broken down . :mad: Thanks ---------- Post updated at 06:34 PM ---------- Previous update was at 05:21 PM ---------- Update : Its a solaris 10 box (1 Reply)
Discussion started by: Solarister
1 Replies

7. Programming

enum and C preprocessor

Say I have a list of enumerations I wish to use to select a variable at compile-time: enum pins { PIN_A=1, PIN_B=7, PIN_C=6, } int VAR1, VAR2, VAR3, VAR4, VAR5, VAR6, VAR7; #define PIN_TO_VAR(NUM) VAR ## NUM int main(void) { PIN_TO_VAR(PIN_A)=32;... (2 Replies)
Discussion started by: Corona688
2 Replies

8. Solaris

How to get spare disks working

Dears how can i make this spare disks working online to replace a defective disks vxdisk list DEVICE TYPE DISK GROUP STATUS c0t10d0s2 sliced - - error c0t11d0s2 sliced disk08 rootdg online c1t16d0s2 sliced ... (3 Replies)
Discussion started by: thecobra151
3 Replies

9. Programming

Mixed enum types - coverity defect

Hi All, I came across this error "MIXING ENUM TYPES" when I run my C program against the Coverity Tool. I've made many search relating to the error, but I didnt find the exact solution. Can anyone help me to overcome this.? Thanks in Advance.!! (3 Replies)
Discussion started by: Parameswaran
3 Replies

10. Solaris

How to determine if i have spare disks in Solaris?

Hi Guys, obviously new to SOLARIS SUN SPARC 5.10 I would really appreciate if you help me see how to find free disks available in my system. Like i am a linux admin. If i want to grow a file system in linux. I would first have a look at my volume groups to see if they have free PEs if not then... (2 Replies)
Discussion started by: aiqbal
2 Replies
Net::DBus::Test::MockIterator(3pm)			User Contributed Perl Documentation			Net::DBus::Test::MockIterator(3pm)

NAME
Net::DBus::Test::MockIterator - Iterator over a mock message SYNOPSIS
Creating a new message my $msg = new Net::DBus::Test::MockMessage my $iterator = $msg->iterator; $iterator->append_boolean(1); $iterator->append_byte(123); Reading from a mesage my $msg = ...get it from somewhere... my $iter = $msg->iterator(); my $i = 0; while ($iter->has_next()) { $iter->next(); $i++; if ($i == 1) { my $val = $iter->get_boolean(); } elsif ($i == 2) { my $val = $iter->get_byte(); } } DESCRIPTION
This module provides a "mock" counterpart to the Net::DBus::Binding::Iterator object which is capable of iterating over mock message objects. Instances of this module are not created directly, instead they are obtained via the "iterator" method on the Net::DBus::Test::MockMessage module. METHODS
$res = $iter->has_next() Determines if there are any more fields in the message itertor to be read. Returns a positive value if there are more fields, zero otherwise. $success = $iter->next() Skips the iterator onto the next field in the message. Returns a positive value if the current field pointer was successfully advanced, zero otherwise. my $val = $iter->get_boolean() $iter->append_boolean($val); Read or write a boolean value from/to the message iterator my $val = $iter->get_byte() $iter->append_byte($val); Read or write a single byte value from/to the message iterator. my $val = $iter->get_string() $iter->append_string($val); Read or write a UTF-8 string value from/to the message iterator my $val = $iter->get_object_path() $iter->append_object_path($val); Read or write a UTF-8 string value, whose contents is a valid object path, from/to the message iterator my $val = $iter->get_signature() $iter->append_signature($val); Read or write a UTF-8 string, whose contents is a valid type signature, value from/to the message iterator my $val = $iter->get_int16() $iter->append_int16($val); Read or write a signed 16 bit value from/to the message iterator my $val = $iter->get_uint16() $iter->append_uint16($val); Read or write an unsigned 16 bit value from/to the message iterator my $val = $iter->get_int32() $iter->append_int32($val); Read or write a signed 32 bit value from/to the message iterator my $val = $iter->get_uint32() $iter->append_uint32($val); Read or write an unsigned 32 bit value from/to the message iterator my $val = $iter->get_int64() $iter->append_int64($val); Read or write a signed 64 bit value from/to the message iterator. An error will be raised if this build of Perl does not support 64 bit integers my $val = $iter->get_uint64() $iter->append_uint64($val); Read or write an unsigned 64 bit value from/to the message iterator. An error will be raised if this build of Perl does not support 64 bit integers my $val = $iter->get_double() $iter->append_double($val); Read or write a double precision floating point value from/to the message iterator my $value = $iter->get() my $value = $iter->get($type); Get the current value pointed to by this iterator. If the optional $type parameter is supplied, the wire type will be compared with the desired type & a warning output if their differ. The $type value must be one of the "Net::DBus::Binding::Message::TYPE*" constants. my $hashref = $iter->get_dict() If the iterator currently points to a dictionary value, unmarshalls and returns the value as a hash reference. my $hashref = $iter->get_array() If the iterator currently points to an array value, unmarshalls and returns the value as a array reference. my $hashref = $iter->get_variant() If the iterator currently points to a variant value, unmarshalls and returns the value contained in the variant. my $hashref = $iter->get_struct() If the iterator currently points to an struct value, unmarshalls and returns the value as a array reference. The values in the array correspond to members of the struct. $iter->append($value) $iter->append($value, $type) Appends a value to the message associated with this iterator. The value is marshalled into wire format, according to the following rules. If the $value is an instance of Net::DBus::Binding::Value, the embedded data type is used. If the $type parameter is supplied, that is taken to represent the data type. The type must be one of the "Net::DBus::Binding::Message::TYPE_*" constants. Otherwise, the data type is chosen to be a string, dict or array according to the perl data types SCALAR, HASH or ARRAY. my $type = $iter->guess_type($value) Make a best guess at the on the wire data type to use for marshalling $value. If the value is a hash reference, the dictionary type is returned; if the value is an array reference the array type is returned; otherwise the string type is returned. my $sig = $iter->format_signature($type) Given a data type representation, construct a corresponding signature string $iter->append_array($value, $type) Append an array of values to the message. The $value parameter must be an array reference, whose elements all have the same data type specified by the $type parameter. $iter->append_struct($value, $type) Append a struct to the message. The $value parameter must be an array reference, whose elements correspond to members of the structure. The $type parameter encodes the type of each member of the struct. $iter->append_dict($value, $type) Append a dictionary to the message. The $value parameter must be an hash reference.The $type parameter encodes the type of the key and value of the hash. $iter->append_variant($value) Append a value to the message, encoded as a variant type. The $value can be of any type, however, the variant will be encoded as either a string, dictionary or array according to the rules of the "guess_type" method. my $type = $iter->get_arg_type Retrieves the type code of the value pointing to by this iterator. The returned code will correspond to one of the constants "Net::DBus::Binding::Message::TYPE_*" my $type = $iter->get_element_type If the iterator points to an array, retrieves the type code of array elements. The returned code will correspond to one of the constants "Net::DBus::Binding::Message::TYPE_*" BUGS
It doesn't completely replicate the API of Net::DBus::Binding::Iterator, merely enough to make the high level bindings work in a test scenario. AUTHOR
Daniel P. Berrange COPYRIGHT
Copyright (C) 2005-2009 Daniel P. Berrange SEE ALSO
Net::DBus::Test::MockMessage, Net::DBus::Binding::Iterator, <http://www.mockobjects.com/Faq.html> perl v5.14.2 2011-06-30 Net::DBus::Test::MockIterator(3pm)
All times are GMT -4. The time now is 10:01 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy