473,796 Members | 2,788 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Style question: #include

I have a program that uses a large lookup table, provided as a large
array in the source:

static int bigtbl[]={123, 456,
/* etc. etc. */
9999 };

Now this table is pretty big, and having it clutter up my main source
file is quite ugly. So I'd like to put it in a separate file and
#include that.

The style question is: should the separate file have a .c or .h
extension? There are two conventions, and I need to violate one of
them!
1) #including a .c file is weird.
2) putting a definition, rather than just declarations, in a .h file
is also weird.

Thoughts?

Jul 6 '07 #1
17 1738

Maybe you can put it in a special named file such as *bigtbl.data*.

Fr************@ googlemail.com writes:
I have a program that uses a large lookup table, provided as a large
array in the source:

static int bigtbl[]={123, 456,
/* etc. etc. */
9999 };

Now this table is pretty big, and having it clutter up my main source
file is quite ugly. So I'd like to put it in a separate file and
#include that.

The style question is: should the separate file have a .c or .h
extension? There are two conventions, and I need to violate one of
them!
1) #including a .c file is weird.
2) putting a definition, rather than just declarations, in a .h file
is also weird.

Thoughts?
Best regards
Xu Weijiang
--
everything has its rules!
Jul 6 '07 #2

<Fr************ @googlemail.com wrote in message
news:11******** **************@ d30g2000prg.goo glegroups.com.. .
>I have a program that uses a large lookup table, provided as a large
array in the source:

static int bigtbl[]={123, 456,
/* etc. etc. */
9999 };

Now this table is pretty big, and having it clutter up my main source
file is quite ugly. So I'd like to put it in a separate file and
#include that.

The style question is: should the separate file have a .c or .h
extension? There are two conventions, and I need to violate one of
them!
1) #including a .c file is weird.
Some might call it weird, others not. But it's perfectly
valid. I'd use either .c or some other extension which
indicates what it is, perhaps .tbl
2) putting a definition, rather than just declarations, in a .h file
is also weird.
Same remarks about 'weird' as above. In a file (whatever its
name) intended to be #included by more than one other file
(the traditional meaning of a 'header file), it would not be
a good idea.

I've also seen the following form in third party libraries I've used:
/* ext.h */
#define EXTERN extern
/* array.h */
EXTERN int array[SIZE];
/* array.c */
#define EXTERN
#include "array.h" /* 'EXTERN' resolves to nothing, so definition occurs */
/* otherfiles.c */
#include ext.h
#include array.h /* causes extern declaration */
I don't really care for that way, I'd probably use
something like a .tbl file

-Mike
Jul 6 '07 #3
Fr************@ googlemail.com wrote:
>
I have a program that uses a large lookup table, provided as a large
array in the source:

static int bigtbl[]={123, 456,
/* etc. etc. */
9999 };

Now this table is pretty big, and having it clutter up my main source
file is quite ugly. So I'd like to put it in a separate file and
#include that.

The style question is: should the separate file have a .c or .h
extension? There are two conventions, and I need to violate one of
them!
1) #including a .c file is weird.
2) putting a definition, rather than just declarations, in a .h file
is also weird.

Thoughts?
No, including a .c file is NOT weird. Being a .c file, you are
warned not to #include it in multiple sources (as you normally can
a .h file). You could also make it a .d or .dat etc. file if you
wish.

--
<http://www.cs.auckland .ac.nz/~pgut001/pubs/vista_cost.txt>
<http://www.securityfoc us.com/columnists/423>
<http://www.aaxnet.com/editor/edit043.html>
cbfalconer at maineline dot net

--
Posted via a free Usenet account from http://www.teranews.com

Jul 6 '07 #4

Francine.Ne...@ googlemail.com wrote:
I have a program that uses a large lookup table, provided as a large
array in the source:

static int bigtbl[]={123, 456,
/* etc. etc. */
9999 };

Now this table is pretty big, and having it clutter up my main source
file is quite ugly. So I'd like to put it in a separate file and
#include that.

The style question is: should the separate file have a .c or .h
extension? There are two conventions, and I need to violate one of
them!
1) #including a .c file is weird.
2) putting a definition, rather than just declarations, in a .h file
is also weird.

Thoughts?
Can you share the logic/Algo which you are runnig on your lookup
table,
Just wanted to know as I also have such a big lookup table, and
my major concern about it is that I need to reduce the search time.
(Optimising)

Can others also help and provide there thoughts.

Thanks
Ranjeet Gupta

Jul 6 '07 #5
On 6 Jul, 04:51, Francine.Ne...@ googlemail.com wrote:
I have a program that uses a large lookup table, provided as a large
array in the source:

static int bigtbl[]={123, 456,
/* etc. etc. */
9999 };

Now this table is pretty big, and having it clutter up my main source
file is quite ugly. So I'd like to put it in a separate file and
#include that.

The style question is: should the separate file have a .c or .h
extension? There are two conventions, and I need to violate one of
them!
1) #including a .c file is weird.
I agree strongly.
2) putting a definition, rather than just declarations, in a .h file
is also weird.
Also agreed. You can conform to both of these by using
the linker...

$ for i in data.h data.c foo.c; do echo "***** $i *****"; cat $i; done
***** data.h *****

#define TBL_SIZE 3
extern int bigtbl[ TBL_SIZE ];
***** data.c *****
#include "data.h"

int bigtbl[ TBL_SIZE ] = { 0, 1, 2};
***** foo.c *****

#include <stdio.h>
#include "data.h"

int
main(void)
{
printf( "Last entry:%d\n", bigtbl[ TBL_SIZE - 1 ]);
return 0;
}
$ gcc -c data.c
$ gcc -c foo.c
$ gcc -o foo foo.o data.o
$ ./foo
Last entry:2

Jul 6 '07 #6
On Jul 5, 10:51 pm, Francine.Ne...@ googlemail.com wrote:
I have a program that uses a large lookup table, provided as a large
array in the source:

static int bigtbl[]={123, 456,
/* etc. etc. */
9999 };

Now this table is pretty big, and having it clutter up my main source
file is quite ugly. So I'd like to put it in a separate file and
#include that.

The style question is: should the separate file have a .c or .h
extension? There are two conventions, and I need to violate one of
them!
1) #including a .c file is weird.
2) putting a definition, rather than just declarations, in a .h file
is also weird.

Thoughts?
When I've done this sort of thing in the past, the #included file was
generated automatically, and did not contain the declaration itself.
It also had the extension ".data". So I'd do something like this in
main.c:

#include <stdio.h /* or whatever you need */

static int bigtbl[] = {
#include "bigtbl.dat a"
};

/* etc. */

HTH,

-=Dave

Jul 6 '07 #7
On Jul 6, 5:23 pm, Dave Hansen <i...@hotmail.c omwrote:
On Jul 5, 10:51 pm, Francine.Ne...@ googlemail.com wrote:


I have a program that uses a large lookup table, provided as a large
array in the source:
static int bigtbl[]={123, 456,
/* etc. etc. */
9999 };
Now this table is pretty big, and having it clutter up my main source
file is quite ugly. So I'd like to put it in a separate file and
#include that.
The style question is: should the separate file have a .c or .h
extension? There are two conventions, and I need to violate one of
them!
1) #including a .c file is weird.
2) putting a definition, rather than just declarations, in a .h file
is also weird.
Thoughts?

When I've done this sort of thing in the past, the #included file was
generated automatically, and did not contain the declaration itself.
It also had the extension ".data". So I'd do something like this in
main.c:

#include <stdio.h /* or whatever you need */

static int bigtbl[] = {
#include "bigtbl.dat a"
};

/* etc. */

HTH,

-=Dave- Hide quoted text -

- Show quoted text -
Hi
How was "bigtb.data " structured ?
Since you have already used curly brackets , is it only values
seperated with commas ?

Jul 6 '07 #8
On Fri, 06 Jul 2007 04:24:34 GMT, "Mike Wahler" wrote:
><Fr*********** *@googlemail.co mwrote:
>1) #including a .c file is weird.

Some might call it weird, others not. But it's perfectly
valid. I'd use either .c or some other extension which
indicates what it is, perhaps .tbl
Microsoft uses .inl (probably means 'inline').
--
Roland Pibinger
"The best software is simple, elegant, and full of drama" - Grady Booch
Jul 6 '07 #9
On Jul 6, 11:48 am, tguclu <tugrul.gu...@g mail.comwrote:
On Jul 6, 5:23 pm, Dave Hansen <i...@hotmail.c omwrote:
[...]
static int bigtbl[] = {
#include "bigtbl.dat a"
};
[...]
>
Hi
How was "bigtb.data " structured ?
Since you have already used curly brackets , is it only values
seperated with commas ?
Exactly. It made the application that generated bigtbl.data a little
easier to write as well.

Regards,

-=Dave

Jul 6 '07 #10

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

Similar topics

12
3835
by: David MacQuigg | last post by:
I have what looks like a bug trying to generate new style classes with a factory function. class Animal(object): pass class Mammal(Animal): pass def newAnimal(bases=(Animal,), dict={}): class C(object): pass C.__bases__ = bases dict = 0
2
2017
by: Mark | last post by:
Hi - I want to allow users of an intranet application, to select their own colours etc. So I have a tbale in my database, which has fields called bgcolour, fontcolour etc. As I want all pages to get the users colours, I have an includes file at the top of each page: <!--#include file="userconfig.asp" --> This is:
35
4556
by: wired | last post by:
Hi, I've just taught myself C++, so I haven't learnt much about style or the like from any single source, and I'm quite styleless as a result. But at the same time, I really want nice code and I go to great lengths to restructure my code just to look concise and make it more manageable. When I say this, I'm also referring to the way I write my functions. It seems to me sometimes that I shouldn't have many void functions accepting...
8
3446
by: Dave Moore | last post by:
I realize this is a somewhat platform specific question, but I think it is still of general enough interest to ask it here ... if I am wrong I guess I will find out 8*). As we all know, DOS uses two characters (carriage-return and line-feed), to signal the end of a line, while UNIX uses only one (line-feed). When using getline in C++, one can only specify a single character as the terminator (default is '\n'), so if you read a line of...
18
2260
by: Exits Funnel | last post by:
Hello, I'm a little confused about where I should include header files and was wondering whether there was some convention. Imagine I've written a class foo and put the definition in foo.h and the implementation of its member functions in foo.cpp (which obviously #inludes foo.h) and further assume that it depends on a class bar which is defined in bar.h. It seems that there are the following two scenarios:
15
3250
by: lawrence | last post by:
Sorry for the dumb question but I'm new to Javascript. I wrote this script hoping to animate some div blocks on a page. You can see the page here: http://www.keymedia.biz/demo.htm Can anyone tell me why these DIVs don't drift to the left as they are supposed to? <script language="javascript">
21
3993
by: Michael Bierman | last post by:
Please forgive the simplicy of this question. I have the following code which attempts to determine the color of some text and set other text to match that color. It works fine in Firefox, but does nothing in IE. I'd be greatful for any assistance. Also, if I will have problems the code on Opera or Safari, I'd appreciate any pointers--I don't have a Mac to test Safari. THanks very much, Michael
33
2509
by: amerar | last post by:
Hi All, I can make a page using a style sheet, no problem there. However, if I make an email and send it out to my list, Yahoo & Hotmail totally ignore the style tags. It looks fine in Netscape though..... Question: I've tried linking & embedding the style tags with no luck. How can I use them inline? I've read that inline style sheets is the way to go if you want them to work in most email clients.......
4
2236
by: jarek | last post by:
Hi, this is my code: CSSStyleDeclaration.prototype.__defineSetter__('display', displaySetter); function displaySetter(value) { var parent = findParent(document, this); if (parent) {
0
9685
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
9533
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10239
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...
1
10190
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10019
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...
1
7555
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
5447
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...
1
4122
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2928
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.