473,789 Members | 2,706 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

best way to declare struct to be used in other c and c++ files

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 #1
10 2485
Tammy wrote:
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?
I define the typedef in the header file
and include this file in all source files that need it.

http://www.mindspring.com/~pfilandr/...ver/e_driver.h

#define E_TYPE struct {char array[40]; d_type data;} e_type
#define D_TYPE long double d_type
typedef D_TYPE;
typedef E_TYPE;

http://www.mindspring.com/~pfilandr/C/e_driver/

--
pete
Sep 6 '08 #2
Tammy wrote:
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;
};
This is the normal way for a public structure declaration, with the
addition of a conditionally compiled extern "C" wrapper for the benefit
of C++ files that include the header.
-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;
};
If you want the details of mystruct to remain hidden, this is also
common practice.

--
Ian Collins.
Sep 6 '08 #3
Tammy <Ta************ *@gmail.comwrit es:
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;
};
That needs to be "typedef struct mystruct mystruct_t;".
-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)
[...]

It depends on whether the client code needs to see the members and/or
declare objects of the type.

With the second approach struct mystruct, and therefore mystruct_t, is
an incomplete type as far as anything with a #include "mystruct.h " is
concerned. That means that client code can declare and manipulate
pointers to the type, but it can't declare objects of the type or
refer to its members.

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Sep 6 '08 #4
pete <pf*****@mindsp ring.comwrites:
Tammy wrote:
>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?

I define the typedef in the header file
and include this file in all source files that need it.

http://www.mindspring.com/~pfilandr/...ver/e_driver.h

#define E_TYPE struct {char array[40]; d_type data;} e_type
#define D_TYPE long double d_type
typedef D_TYPE;
typedef E_TYPE;

http://www.mindspring.com/~pfilandr/C/e_driver/
That's a very odd use of macros; I find it extremely counterintuitiv e.

Looking at the web page, it makes *some* sense in context. You have
(I'm abbreviating this):

#define STRUCTURES 0 /* 0 or 1, This is the line to change */

#if STRUCTURES == 0 /* Not this one */

#define E_TYPE long unsigned e_type
#define D_TYPE long unsigned d_type

#else

#define E_TYPE struct {char array[40]; d_type data;} e_type
#define D_TYPE long double d_type

#endif

typedef D_TYPE;
typedef E_TYPE;

I'm sure there's some good reason to conditionally define E_TYPE and
D_TYPE either as unsigned long or as a struct and a long double; I
haven't read enough of the code to understand what that reason might
be. But I definitely wouldn't write it that way. I'd probably write
something more like this:

#undef STRUCTURES /* defined or undefined

#ifdef STRUCTURES

typedef long double d_type;
typedef struct {char array[40]; d_type data;} e_type;

#else

typedef unsigned long d_type;
typedef unsigned long e_type;

#endif

In any case, your code sample illustrates the use of the preprocessor
to conditionally define types in one of two different ways, which
isn't what the OP was asking about.

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Sep 6 '08 #5
Keith Thompson wrote:
pete <pf*****@mindsp ring.comwrites:
>Tammy wrote:
>>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?
I define the typedef in the header file
and include this file in all source files that need it.

http://www.mindspring.com/~pfilandr/...ver/e_driver.h

#define E_TYPE struct {char array[40]; d_type data;} e_type
#define D_TYPE long double d_type
typedef D_TYPE;
typedef E_TYPE;

http://www.mindspring.com/~pfilandr/C/e_driver/

That's a very odd use of macros; I find it extremely counterintuitiv e.

Looking at the web page, it makes *some* sense in context. You have
(I'm abbreviating this):

#define STRUCTURES 0 /* 0 or 1, This is the line to change */

#if STRUCTURES == 0 /* Not this one */

#define E_TYPE long unsigned e_type
#define D_TYPE long unsigned d_type

#else

#define E_TYPE struct {char array[40]; d_type data;} e_type
#define D_TYPE long double d_type

#endif

typedef D_TYPE;
typedef E_TYPE;

I'm sure there's some good reason to conditionally define E_TYPE and
D_TYPE either as unsigned long or as a struct and a long double;
I prefer to have the readily changeable parts of the program,
be macros.
The program also prints out the stringized macros.

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)

For example, I was looking at:
http://www.pobox.com/~qed/sort.html
which redirected me to
http://www.azillionmonkeys.com/qed/sort.html
and I downloaded the program at this link:
http://www.azillionmonkeys.com/qed/sorttest.c

and since I like to race sorting functions,
I changed the name of the program to pq_test
and replaced the definition of main with this:

#include "test_sort. h"

#define str(s) # s
#define xstr(s) str(s)

int main (void)
{
int seed = 0;
double r0, r1, r2, r3, r4, r5, r6, r7;

/* Warm up the cache */
{
int i;
for (i = 0; i < NUM_ITEMS; i++) numbers[i] = i;
heapSort (numbers, NUM_ITEMS);
}

r0 = timetest (seed, heapSort);
r1 = timetest (seed, quickSort);
r2 = timetest (seed, mergeSort);
r3 = NUM_ITEMS 600 ? 0 : timetest (seed, insertSort);
r4 = timetest (seed, hsortmwrapper);
r5 = timetest (seed, pqsortwrapper);
r6 = timetest (seed, stablewrapper);
r7 = NUM_ITEMS 600 ? 0 : timetest (seed, sisortwrapper);

puts("/* BEGIN pq_test.c output */\n");
puts("#define NUM_ITEMS " xstr(NUM_ITEMS) "\n");
printf (" heapsort: %.3f\n", r0);
printf (" quicksort: %.3f\n", r1);
printf (" mergesort: %.3f\n", r2);
printf ("insertsort : %.3f\n", r3);
putchar('\n');
printf (" hsortm: %.3f\n", r4);
printf (" pqsort: %.3f\n", r5);
printf (" stable: %.3f\n", r6);
printf (" sisort: %.3f\n", r7);
puts("\n/* END pq_test.c output */");

return 0;
}

Then I got these results:

/* BEGIN pq_test.c output */

#define NUM_ITEMS 6000

heapsort: 4.594
quicksort: 3.375
mergesort: 4.531
insertsort: 0.000

hsortm: 4.296
pqsort: 2.562
stable: 3.640
sisort: 0.000

/* END pq_test.c output */

Then I changed NUM_ITEMS to 600 and got these results:

/* BEGIN pq_test.c output */

#define NUM_ITEMS 600

heapsort: 0.375
quicksort: 0.265
mergesort: 0.359
insertsort: 2.406

hsortm: 0.344
pqsort: 0.203
stable: 0.281
sisort: 1.125

/* END pq_test.c output */

I also wrote 4 files to complete the program:
test_sort.h
test_sort.c
pqsort.h
pqsort.c

The point of doing it that way, is that the file,
pqsort.c, can be used as is, to sort arrays of any type,
without changing even a single byte.

The files look like this:

/* BEGIN test_sort.h */

#ifndef H_TEST_SORT_H
#define H_TEST_SORT_H

void hsortmwrapper(i nt numbers[], int qty);
void pqsortwrapper(i nt numbers[], int qty);
void stablewrapper(i nt numbers[], int qty);
void sisortwrapper(i nt numbers[], int qty);

#endif

/* END test_sort.h */
/* BEGIN test_sort.c */

#include <assert.h>

#include "test_sort. h"
#include "pqsort.h"

void hsortmwrapper(i nt numbers[], int qty)
{
hsortm(numbers, qty);
}

void pqsortwrapper(i nt numbers[], int qty)
{
assert(SMALL_PA RTITION >= 4);
pqsort(numbers, qty);
}

void stablewrapper(i nt numbers[], int qty)
{
assert(SMALL_ME RGE >= 1);
stable(numbers, qty);
}

void sisortwrapper(i nt numbers[], int qty)
{
sisort(numbers, qty);
}

/* END test_sort.c */
/* BEGIN pqsort.h */

#ifndef H_PQSORT_H
#define H_PQSORT_H

#include <stddef.h>

#define E_TYPE int e_type
#define MOV(A, B) ((void)(*(A) = *(B)))
#define GT(A, B) (*(A) *(B))
#define SMALL_PARTITION 24
#define SMALL_MERGE 32

typedef E_TYPE;
/*
** (hsortm) is a double siftdown, casual heapsort.
*/
void hsortm(e_type *array, size_t nmemb);
/*
** (pqsort) is an introspective, median of three, quicksort.
*/
void pqsort(e_type *array, size_t nmemb);
/*
** (stable) is a stable merge sort / insertion sort.
*/
void stable(e_type *array, size_t nmemb);
/*
** (sisort) is a stable insertion sort.
*/
void sisort(e_type *array, size_t nmemb);

#endif

/* END pqsort.h */
/* BEGIN pqsort.c */

#include <stdlib.h>

#include "pqsort.h"

#define SWAP(A, B, T) \
(MOV((T), (A)), MOV((A), (B)), MOV((B), (T)))
#define SORT_3(A, B, C, T) \
if (GT((A), (B))) { \
MOV((T), (A)); \
if (GT((C), (B))) { \
MOV((A), (B)); \
if (GT((T), (C))) { \
MOV((B), (C)); \
MOV((C), (T)); \
} else { \
MOV((B), (T)); \
} \
} else { \
MOV((A), (C)); \
MOV((C), (T)); \
} \
} else { \
if (GT((B), (C))) { \
MOV((T), (B)); \
if (GT((A), (C))) { \
MOV((B), (A)); \
MOV((A), (C)); \
} else { \
MOV((B), (C)); \
} \
MOV((C), (T)); \
} \
}
#define SIFTDOWNM(P) \
{ \
parent = (P); \
child = parent * 2; \
MOV(&temp, array + parent); \
while (nmemb - parent parent) { \
if (GT(array + child + 1, array + child)) { \
++child; \
} \
if (GT(array + child, &temp)) { \
MOV(array + parent, array + child); \
parent = child; \
child *= 2; \
} else { \
break; \
} \
} \
if (nmemb == child && GT(array + child, &temp)) { \
MOV(array + parent, array + child); \
parent = child; \
} \
MOV(array + parent, &temp); \
}

static void pqloop(e_type *array, size_t nmemb, size_t d);
static void merge(e_type *array, size_t nmemb, e_type *buff);

void hsortm(e_type *array, size_t nmemb)
{
size_t p, child, parent;
e_type temp;

if (nmemb 1) {
p = --nmemb / 2;
do {
SIFTDOWNM(p);
} while (p-- != 0);
SWAP(array, array + nmemb, &temp);
while (--nmemb != 0) {
SIFTDOWNM(0);
SWAP(array, array + nmemb, &temp);
}
}
}

void pqsort(e_type *array, size_t nmemb)
{
size_t d, n;

d = 2;
for (n = nmemb / 4; n != 0; n /= 2) {
++d;
}
pqloop(array, nmemb, 2 * d);
}

void stable(e_type *array, size_t nmemb)
{
e_type *buff = malloc(nmemb / 2 * sizeof *buff);

if (buff != NULL) {
merge(array, nmemb, buff);
free(buff);
} else {
sisort(array, nmemb);
}
}

void sisort(e_type *array, size_t nmemb)
{
e_type *base, *low, *high, temp;

if (nmemb-- 1) {
base = array;
do {
low = array++;
if (GT(low, array)) {
high = array;
MOV(&temp, high);
do {
MOV(high, low);
if (--high == base) {
break;
}
--low;
} while (GT(low, &temp));
MOV(high, &temp);
}
} while (--nmemb != 0);
}
}

static void pqloop(e_type *array, size_t nmemb, size_t d)
{
e_type *i, *j, temp;

while (nmemb SMALL_PARTITION ) {
if (!d--) {
hsortm(array, nmemb);
return;
}
i = 1 + array;
j = --nmemb + array;
SORT_3(j, array, i, &temp);
do {
SWAP(j, i, &temp);
do {
++i;
} while (GT(array, i));
do {
--j;
} while (GT(j, array));
} while (j i);
SWAP(array, j, &temp);
pqloop(j + 1, nmemb + array - j, d);
nmemb = j - array;
}
sisort(array, nmemb);
}

static void merge(e_type *array, size_t nmemb, e_type *buff)
{
if (nmemb SMALL_MERGE) {
e_type *mid_ptr;
size_t const half = nmemb / 2;
e_type *const after_buff = buff + half;
e_type *const middle = array + half;
e_type *const after_array = array + nmemb;

merge(middle, nmemb - half, buff);
merge(array, half, buff);
do {
if (GT(array, middle)) {
mid_ptr = middle;
buff = after_buff;
do {
--buff;
--mid_ptr;
MOV(buff, mid_ptr);
} while (array != mid_ptr);
MOV(array, middle);
mid_ptr = middle + 1;
while (middle != ++array) {
if (GT(buff, mid_ptr)) {
MOV(array, mid_ptr);
++mid_ptr;
} else {
MOV(array, buff);
++buff;
}
}
while (after_buff != buff) {
if (after_array != mid_ptr) {
if (GT(buff, mid_ptr)) {
MOV(array, mid_ptr);
++mid_ptr;
} else {
MOV(array, buff);
++buff;
}
++array;
} else {
do {
MOV(array, buff);
++array;
++buff;
} while (after_buff != buff);
break;
}
}
break;
} else {
++array;
}
} while (middle != array);
} else {
sisort(array, nmemb);
}
}

/* END pqsort.c */
--
pete
Sep 6 '08 #6
ac
On Sat, 06 Sep 2008 07:50:47 +0100, pete <pf*****@mindsp ring.comwrote:
I prefer to have the readily changeable parts of the program,
be macros.
The program also prints out the stringized macros.

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)

For example, I was looking at:
http://www.pobox.com/~qed/sort.html
which redirected me to
http://www.azillionmonkeys.com/qed/sort.html
and I downloaded the program at this link:
http://www.azillionmonkeys.com/qed/sorttest.c

and since I like to race sorting functions,
I changed the name of the program to pq_test
and replaced the definition of main with this:
Maybe a potential problem with this E_TYPE is we can only define one
etype_t in one C source file, which means we cannot sort an integer array
and a double array in the same C source file. Is that true? I think a
better way to achieve generic types is this example, using token
concatenation:

http://www.freewebs.com/attractivechaos/ksort.h.html
http://www.freewebs.com/attractivech...rt_test.c.html

No function calls are made for comparisons, either.

BTW, it seems that you have implemented really efficient sorting
functions! How is it compared to STL sort?

Thanks,

-ac
Sep 6 '08 #7
ac wrote:
On Sat, 06 Sep 2008 07:50:47 +0100, pete <pf*****@mindsp ring.comwrote:
>I prefer to have the readily changeable parts of the program,
be macros.
The program also prints out the stringized macros.

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)

For example, I was looking at:
http://www.pobox.com/~qed/sort.html
which redirected me to
http://www.azillionmonkeys.com/qed/sort.html
and I downloaded the program at this link:
http://www.azillionmonkeys.com/qed/sorttest.c

and since I like to race sorting functions,
I changed the name of the program to pq_test
and replaced the definition of main with this:

Maybe a potential problem with this E_TYPE is we can only define one
etype_t
I've heard that etype_t is reserved under POSIX rules,
which is why I write e_type.
in one C source file, which means we cannot sort an integer
array and a double array in the same C source file. Is that true?
Yes.
I think a better way to achieve generic types is this example,
using token concatenation:

http://www.freewebs.com/attractivechaos/ksort.h.html
http://www.freewebs.com/attractivech...rt_test.c.html

No function calls are made for comparisons, either.
Thank you.
That's very interesting to me.
I have no experience with ##.
Maybe it's about time for me to become more familiar with it.
BTW, it seems that you have implemented really efficient sorting
functions!
Thank you. It's a hobby of mine.
How is it compared to STL sort?
It's actually Dann Corbit's C version of STL sort.
It's a smidgeon slower.

--
pete
Sep 7 '08 #8
ac
On Sun, 07 Sep 2008 03:20:21 +0100, pete <pf*****@mindsp ring.comwrote:
That's very interesting to me.
I have no experience with ##.
Maybe it's about time for me to become more familiar with it.
If you are interested in this method, you may also have a look at this
header file:

http://www.freebsd.org/cgi/cvsweb.cg...sys/sys/tree.h

This file is part of freebsd. It implements a splay tree and a rb tree,
allowing for generic types.

-ac
Sep 7 '08 #9
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))
/* --------- */
/* pp_sort.h */
/* --------- */

/* #include "pp_util.h" */
#include <stddef.h>

#define pp_sort(T, a, n) \
pp_concat(sort_ , T)(a, n)

#define pp_decl_sort(T) \
void pp_concat(sort_ , T)(pp_t(T) *, size_t)

/* trivial for sake of demo */
#define pp_defn_sort(T, lt_pp, assign_pp) \
void pp_concat(sort_ , T)( pp_t(T) *a, \
size_t n ) \
{ \
size_t i, j, k; \
pp_t(T) t; \
\
for (i = 0; i < n - 1; i++) \
{ \
for (k = i, j = i + 1; j < n; j++) \
if (lt_pp(a[j], a[i])) \
k = j; \
\
if (k != i) \
{ \
assign_pp(t, a[i]); \
assign_pp(a[i], a[k]); \
assign_pp(a[k], t ); \
} \
} \
}

pp_decl_sort(in t); /* built-ins */
/* ----------- */
/* gauss_int.h */
/* ----------- */

typedef int gauss_int_t[2];
pp_decl_sort(ga uss_int);
/* ------ */
/* main.c */
/* ------ */

/* #include "gauss_int. h" */
/* #include "pp_sort.h" */
#include <stdio.h>

#define countof(x) \
((size_t) (sizeof(x)/sizeof*(x)))

int main(void)
{
int ai[] = { 2, -4, 8, -16 };
gauss_int_t gi[] = { { 2, -4},
{ -8, 16 },
{32, -64},
{-128, 256} };
size_t i;

/* Integers */
for (i = 0; i < countof(ai); i++)
printf(" %d", ai[i]);
puts("");

sort_int(ai, countof(ai));

for (i = 0; i < countof(ai); i++)
printf(" %d", ai[i]);
puts("\n");

/* Gaussian Integers */
for (i = 0; i < countof(ai); i++)
printf(" (%d, %d)", gi[i][0], gi[i][1]);
puts("");

sort_gauss_int( gi, countof(gi));

for (i = 0; i < countof(ai); i++)
printf(" (%d, %d)", gi[i][0], gi[i][1]);
puts("");

return 0;
}
/* ------ */
/* sort.c */
/* ------ */

/* #include "pp_sort.h" */

pp_defn_sort(in t, pp_lt, pp_assign)
/* ----------- */
/* gauss_int.c */
/* ----------- */

/* #include "pp_util.h" */
/* #include "pp_sort.h" */
#include <string.h>

#define pp_gauss_lt(a, b) \
( pp_lt( (a)[0], (b)[0] ) ? 1 \
: pp_lt( (b)[0], (a)[0] ) ? 0 \
: pp_lt( (a)[1], (b)[1] ) )

pp_defn_sort(ga uss_int, pp_gauss_lt, pp_memcpy)

% acc sort.c

% a
2 -4 8 -16
-16 -4 2 8

(2, -4) (-8, 16) (32, -64) (-128, 256)
(-128, 256) (-8, 16) (2, -4) (32, -64)

%

--
Peter
Sep 8 '08 #10

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

Similar topics

19
3086
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
1
4742
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...
15
5327
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;
14
6705
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...
5
348
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
6
1803
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;
27
5519
by: arkmancn | last post by:
Any comments? thanks. Jim
2
281
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
2
2360
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 {
0
9666
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
10410
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10200
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
10139
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
9984
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
9020
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...
0
5418
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...
2
3701
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2909
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.