Solved

Table in DLL

Posted on 1997-05-04
2
251 Views
Last Modified: 2010-04-15
have a C module containing several functions. In each of the function
I have a Table of 256 entries based on a struct...


        struct  MYTABLE
        {
                unsigned char text[10];
                unsigned char outtext[10];
        };          

        //unsigned int y;
    //static unsigned char chr;    
    //unsigned int chr;
        // 255 enheter av strukten hvor hver innholder karakterstrengen    
struct MYTABLE Table[256];
        strcpy(Table[9].text,"&newlin;");    
        strcpy(Table[9].outtext,"\x09");    


I use the Table for converting strings, checking against the Table.text
writing out the contents of the Table.outtext.

This Table is initalized every time a string is passed to it. Is it
possible to locate the Table outside the function, making it possible so
that the table is only initialized once, when the DLL is loaded??

Is it a better/faster way to initialize the elements in the Table than
using strcpy?


Help
0
Comment
Question by:geira
2 Comments
 
LVL 1

Accepted Solution

by:
prc earned 0 total points
ID: 1250244
Yes to both - use static initialisers like this:

struct MYTABLE table[256] =
{
  { "&",         "&" },
  { "&lt;",          "<" },
  /* ... etc ... */
  { "&last-entry;",  "\xff" }
};

That's your lot for a measly 5 points! ;-)

0
 

Author Comment

by:geira
ID: 1250245
Fine answer! Thanks...
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question