473,624 Members | 2,290 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Create readonly array of data?

I want to create a readonly array of data, then a readonly array of a
structure. This is data I access but I want it protected against
accidental change. The following is my test code.

#include "stdafx.h"

struct LVC
{
unsigned short int lo;
unsigned short int hi;
};

void main()
{
//This seems to work
static const unsigned short int LV[4] =
{0xAC00,
0xAC1C,
0xAC38,
0xAC54 };

//THIS DOESN'T WORK. COMPILER COMPLAINS
static const struct LVC[4] = {
{ 0xAC01, 0xAC1B },
{ 0xAC1D, 0xAC37 },
{ 0xAC39, 0xAC53 },
{ 0xAC55, 0xAC6F },
};

unsigned short i,j;

i = LVC[2].lo;
j = LVC[2].hi;
}

I'm using Microsoft Visual C++ Express Edition
(I'd also like to get rid of that #include "stdafx.h" if
there's some compiler configuration that will allow me
to do that.)
Jan 1 '07 #1
14 4393
Susan Rice a écrit :
//THIS DOESN'T WORK. COMPILER COMPLAINS
static const struct LVC[4] = {
static const struct LVC is the type. You have to give a *name*
to that array.

for instance
static const struct LVC MyTable[4] = {
etc

Then you use THAT name:
i = MyTable[2].lo;
j = MyTable[2].hi;

jacob

P.S.
it is not void main() but int main(void).
But that is a detail.

---
http://www.cs.virginia.edu/~lcc-win32
A free C compiler for windows
Jan 1 '07 #2
Susan Rice wrote:
I want to create a readonly array of data, then a readonly array of a
structure. This is data I access but I want it protected against
accidental change. The following is my test code.

#include "stdafx.h"
See below about this.
struct LVC
It's generally prefered by most to reserve all caps for macros.
{
unsigned short int lo;
unsigned short int hi;
};

void main()
This should be int main(void)
{
//This seems to work
static const unsigned short int LV[4] =
{0xAC00,
0xAC1C,
0xAC38,
0xAC54 };

//THIS DOESN'T WORK. COMPILER COMPLAINS
static const struct LVC[4] = {
LVC is the name of struct type that you created above. What you wanted
was something like:

static const struct LVC LVC_array[4] = {
{ 0xAC01, 0xAC1B },
{ 0xAC1D, 0xAC37 },
{ 0xAC39, 0xAC53 },
{ 0xAC55, 0xAC6F },
};

unsigned short i,j;

i = LVC[2].lo;
j = LVC[2].hi;
Then change these two names as well.
}

I'm using Microsoft Visual C++ Express Edition
(I'd also like to get rid of that #include "stdafx.h" if
there's some compiler configuration that will allow me
to do that.)
This has to do with pre-compiled headers in VC++. I don't know
specifically to correct that in Express, but check your project
settings to remove any dependence. If you can't figure it out, you'll
need a Microsoft newsgroup.


Brian
Jan 1 '07 #3


I'm using Microsoft Visual C++ Express Edition
(I'd also like to get rid of that #include "stdafx.h" if
there's some compiler configuration that will allow me
to do that.)
when u create your project in msvc++

new project->Win32(win32 console app template is automatically
selected) ->
(enter a name for the project)->next->select "empty project"
option->finish

then add the header and source files that u need.

and more simply...
new project->select "general " option from the Project type window
->finish

//THIS DOESN'T WORK. COMPILER COMPLAINS
static const struct LVC[4] = {
{ 0xAC01, 0xAC1B },
u did not name the "template" ..it has been answered above

regards

Jan 1 '07 #4
"rhle.freak " wrote:
>
>I'm using Microsoft Visual C++ Express Edition
(I'd also like to get rid of that #include "stdafx.h" if
there's some compiler configuration that will allow me
to do that.)

when u create your project in msvc++
U never posted in this thread. I don't believe he even uses
c.l.c. If you refrained from snipping attributions it would be
easier to follow this. In addition msvc++ is system specific and
off-topic here.

--
Merry Christmas, Happy Hanukah, Happy New Year
Joyeux Noel, Bonne Annee.
Chuck F (cbfalconer at maineline dot net)
<http://cbfalconer.home .att.net>
Jan 1 '07 #5
CBFalconer said:
"rhle.freak " wrote:
>>
>>I'm using Microsoft Visual C++ Express Edition
(I'd also like to get rid of that #include "stdafx.h" if
there's some compiler configuration that will allow me
to do that.)

when u create your project in msvc++

U never posted in this thread. I don't believe he even uses
c.l.c.
I believe he has done so (although I admit it may have been cp rather than
clc) - a month or so ago.

If you refrained from snipping attributions it would be
easier to follow this. In addition msvc++ is system specific and
off-topic here.
Will you not take pity on someone who appears to be trying to coax his
Microsoft implementation into conforming mode?

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Jan 1 '07 #6
"rhle.freak " <rh********@gma il.comwrites:
[...]
when u create your project in msvc++
[...]
then add the header and source files that u need.
[...]
u did not name the "template" ..it has been answered above
Please don't use silly abbreviations like "u" for "you". It makes
your articles harder to read, and a lot of people just won't bother.

And please don't snip attribution lines (lines of the form
"So-and-so writes:").

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Jan 1 '07 #7


On Jan 1, 7:57 pm, CBFalconer <cbfalco...@yah oo.comwrote:
"rhle.freak " wrote:
I'm using Microsoft Visual C++ Express Edition
(I'd also like to get rid of that #include "stdafx.h" if
there's some compiler configuration that will allow me
to do that.)
when u create your project in msvc++U never posted in this thread. I don't believe he even uses
c.l.c. If you refrained from snipping attributions it would be
easier to follow this. In addition msvc++ is system specific and
off-topic here.

--
please do check the earlier thread "stack" which i had posted a few
days ago! ! regarding using msvc++ ,yes its a specific problem and off
topic but there is no harm if i am using the same compiler n can help
someone with something really simple and please do forgive me because
i am new to using Usenet
(Google groups to be specific) and my format of posting was wrong,i
will definitely try to improve on that!!

Jan 2 '07 #8
"rhle.freak " wrote:
CBFalconer <cbfalco...@yah oo.comwrote:
>"rhle.freak " wrote:
>>I'm using Microsoft Visual C++ Express Edition
(I'd also like to get rid of that #include "stdafx.h" if
there's some compiler configuration that will allow me
to do that.)
>>when u create your project in msvc++

U never posted in this thread. I don't believe he even uses
c.l.c. If you refrained from snipping attributions it would be
easier to follow this. In addition msvc++ is system specific and
off-topic here.

please do check the earlier thread "stack" which i had posted a few
days ago! ! regarding using msvc++ ,yes its a specific problem and off
topic but there is no harm if i am using the same compiler n can help
someone with something really simple and please do forgive me because
i am new to using Usenet
(Google groups to be specific) and my format of posting was wrong,i
will definitely try to improve on that!!
'Another thread' has nothing to do with it. Articles need to stand
alone. That is the point of quoting relevant matter. You would be
well advised to get a proper newsreader and access usenet directly
instead of through the flawed google interface. Also never use
silly geekspeak, such as 'u' and 'n' abbreviations. They only
serve to annoy and make reading hard, especially for non-English
speakers.

Just delete the #include <stdafx.hand #include the appropriate
standard C includes. The C-library link below will be useful, as
will the C99 standard.

Some useful references about C:
<http://www.ungerhu.com/jxh/clc.welcome.txt >
<http://www.eskimo.com/~scs/C-faq/top.html>
<http://benpfaff.org/writings/clc/off-topic.html>
<http://anubis.dkuug.dk/jtc1/sc22/wg14/www/docs/n869/(C99)
<http://www.dinkumware. com/refxc.html (C-library}
<http://gcc.gnu.org/onlinedocs/ (GNU docs)
<http://clc-wiki.net (C-info)

Some informative links about posting:
<http://members.fortune city.com/nnqweb/ (newusers)
<http://www.catb.org/~esr/faqs/smart-questions.html>
<http://www.caliburn.nl/topposting.html >
<http://www.netmeister. org/news/learn2quote.htm l>
<http://cfaj.freeshell. org/google/ (taming google)

--
Merry Christmas, Happy Hanukah, Happy New Year
Joyeux Noel, Bonne Annee.
Chuck F (cbfalconer at maineline dot net)
<http://cbfalconer.home .att.net>
Jan 2 '07 #9

CBFalconer wrote:
"rhle.freak " wrote:
CBFalconer <cbfalco...@yah oo.comwrote:
"rhle.freak " wrote:
<snip>
alone. That is the point of quoting relevant matter. You would be
well advised to get a proper newsreader and access usenet directly
instead of through the flawed google interface. Also never use
<snip>

How do I access usenet directly?
For free ?

Regards,
Frodo B

Jan 2 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
4073
by: Nick | last post by:
Loop to create an array from a dynamic form. I'm having trouble with an application, and I'll try to explain it as clearly as possible: 1. I have a form with two fields, say Apples and Oranges. The user selects from a drop down menu, between 1-10 of each and clicks submit. The resulting page will display a NEW form, with rows and a list of fields for the amount of each items selected.
7
1468
by: Piotre Ugrumov | last post by:
I have tried to write the class Student(Studente), Teacher(Docente). This classes derive from the class Person. In a class university(facoltà). I have tried to create an array of Student and an array of Teacher, but the compiler give me an error. How can I do to go on? Here I have copied the Student, Teacher and University classes. Thanks Student class:
6
2364
by: billy | last post by:
I've got a set of subclasses that each derive from a common base class. What I'd like to do is create a global array of the class types (or, class names) that a manager class can walk through in its constructor and instantiate one of each of the class types in this global array. So, it's almost like the global array has to hold data types as opposed to data. Basically, I currently have to add the items manually 1 at a time.
8
5226
by: ljlevend2 | last post by:
If a property's type is an array and the property is exposed in a PropertyGrid, then the property can be expanded so that the user can view and edit the array elements. But, I've noticed that if the property is ReadOnly then the expanded array elements can still be edited. I need to make the elements ReadOnly if the property is ReadOnly. Is this possible? Thank you, Lance
2
1333
by: garyusenet | last post by:
I am writing a programme that when run will list the current internet explorer windows open, and allow the user to choose which one they would like to work with. At the moment I have managed to get as far as finding open windows, and detecting which ones are internet explorer windows, but I do not know how to store the ones that are internet explorer windows and reference them later. My idea was that I could create an array of type...
2
1648
by: Big Charles | last post by:
Hello, I would like to create an array-class to be able to call like: Dim oMyCar as New MyCar ' After initializing oMyCar, the object has to be like: oMyCar(0).Brand oMyCar(0).Wheels.NumberOfWheels oMyCar(0).Wheels.ColorOfWheels
11
4642
by: memeticvirus | last post by:
I have an array cli::array<float, 2and I would like to access a subset of it's values by compiling an array of pointers. But, it's not possible to create an array of type cli:array<cli::interior_ptr<float>, 2>... So, what do I do?
1
2377
by: eihabisaac | last post by:
hey i need to create an array of objects then to use it in a list control,, - im asking the user to enter data using textboxes and combo box in a dialog then he click ok ... -after the ok i want it to be inserted in the array so i can use it later ... -this operation will loop until he decide to stop ...
3
4839
by: David K in San Jose | last post by:
I'm using managed (CLR) C++ in VS2005 to create a Windows app that contains a form named "MyForm". In the code for that form I'm trying to invoke some static functions by using an array of function pointers (delegates). I assume I need to use the array< T keyword to allocate an array of delegates, and then initialize the array by setting each array element to the pointers (handles) of the functions I'll be invoking. I've been trying to...
0
8242
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8629
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8488
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7170
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6112
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5570
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4084
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4183
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1488
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.