Hello all,
I am wondering what is the best way to declare a struct to be used in
other c and c++ files. Such as for a C API that will be used by
others.
1. Declaring the typedef and the struct in the header file and
including this file in all source files that need it? For example:
mystruct.h
typedef mystruct mystruct_t;
struct mystruct {
int x;
char c;
};
-OR-
2. Declaring the typedef in a header file and declaring the struct in
the .c file ( I am not certain that this will work). For example:
mystruct.h
typedef mystruct mystruct_t;
mystruct.c
#include "mystruct.h "
struct mystruct {
int x;
char c;
};
......(other code using the structure)
-OR-
3. Other methods??
Thanks in advance for your help,
Tammy
Sep 6 '08
10 2488
Peter Nilsson wrote:
pete <pfil...@mindsp ring.comwrote:
>...The proper use of of the e_type interface, is to define at least these three macros in a header file, (there may be other macros depending on the sort algorithm) for sorting functions which can then be used to sort arrays of elements of any type, including arrays of arrays:
#define E_TYPE #define MOV(A, B) #define GT(A, B)
I prefer to make the configurable components of the sort
template functions as macro parameters. [The following is
just proof of concept. File break up requires (re)insertion
of include guards and other details.]
%type sort.c
/* --------- */
/* pp_util.h */
/* --------- */
#define pp_cat(a, b) a ## b
#define pp_concat(a, b) pp_cat(a, b)
#define pp_t(T) pp_concat(T, _t)
typedef int int_t; /* and the rest */
#define pp_lt(a, b) ((a) < (b))
#define pp_assign(a, b) ((a) = (b))
#define pp_memcpy(a, b) memcpy(a, b, sizeof(a))
Thank you.
I'll give it a good look.
--
pete This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Geetesh |
last post by:
Recently i saw a code in which there was a structer defination similar
as bellow:
struct foo
{
int dummy1;
int dummy2;
int last
};
In application the above array is always allocated at runtime using
malloc.In this last member of the structer "int last" is not
|
by: mrhicks |
last post by:
Hello all,
I am trying to keep my coding easy for everyone to use. I have some
ARINC data that need to go out which 12 Bytes long. The first byte is
the command word, the next 10 bytes represent 40 devices in the system
with four command that can be issue per device. So within the each
byte of the 10 bytes a command comprises 4 device. The last byte is a
send flag.
I first tried creating a struct like the following...
|
by: Geoff Cox |
last post by:
Hello,
Can I separately declare and initialize a string array? How and where
would I do it in the code below? It was created using Visual C++ 2005
Express Beta 2 ...
In C# I would have
private string myArray;
|
by: Jon Rea |
last post by:
I am currently cleaning up an application which was origainlly hashed
together with speed of coding in mind and therefore contains quite a few
"hacky" shortcuts.
As part of this "revamping" process I am introducing namespaces to
properly compartmentalise sections of the code into logical units. What
I am speciffically trying to get right is the dependency tree for header
files to reduce compile time and simplify the code structure.
On...
|
by: sherifffruitfly |
last post by:
Hi,
I'm just learning cpp, and the exercise I'm working on is basically as
follows:
1) Create a struct type with 4 members (char, char, char, int).
2) Create an array of, say 3 instances of the struct, and populate them
with data.
3) cin 1, 2, 3, or 4 from the user
4) If the user selected, say, 2, display the contents of the 2nd data
| |
by: Amit_Basnak |
last post by:
Dear Friends
I have two structures as below
typedef struct {
long_int length;
char data;
} CI_STRUCT_DATA;
typedef CI_STRUCT_DATA *ptr_CiStructData;
|
by: arkmancn |
last post by:
Any comments? thanks.
Jim
|
by: beet |
last post by:
Hi all,
I tried to declare a c++ struct like following in a header file; I
want to include
this header file in other files to create and access this struct.
------
1 #ifndef _SEARCHDATA_H_
2 #define _SEARCHDATA_H_
3
|
by: stephen.diverdi |
last post by:
I have a question about what's the best way to handle something in C++
without a lot of redundant code and void*s because I don't seem to be
able to avoid them both. I've run into it before and always sort of
hacked something together, but I'd really prefer a more elegant
solution.
I have a parameter struct that I store some values of varying type in:
struct params_t
{
|
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...
|
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,...
| |
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...
|
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,...
|
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...
|
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...
|
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...
|
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
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |