LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-07-2024, 05:57 PM   #1
errigour
Member
 
Registered: May 2009
Posts: 373

Rep: Reputation: 6
is this ok in a header file for c?


Just wonder if I can put that in a header file and use it.
Code:
struct a {
    struct *b;
};

struct b {
    struct *a;
};
 
Old 06-07-2024, 07:42 PM   #2
smallpond
Senior Member
 
Registered: Feb 2011
Location: Massachusetts, USA
Distribution: Fedora
Posts: 4,196

Rep: Reputation: 1284Reputation: 1284Reputation: 1284Reputation: 1284Reputation: 1284Reputation: 1284Reputation: 1284Reputation: 1284Reputation: 1284
Your syntax is not correct. Are you trying to do:

Code:
struct a {
    struct b *b;
};

struct b {
    struct a *a;
};
 
2 members found this post helpful.
Old 06-07-2024, 07:54 PM   #3
errigour
Member
 
Registered: May 2009
Posts: 373

Original Poster
Rep: Reputation: 6
Quote:
Originally Posted by smallpond View Post
Your syntax is not correct.
Your right mb that's what I meant but will it work and compile right? i want both structs to be accessed from each other.
 
Old 06-07-2024, 07:57 PM   #4
Mechanikx
Member
 
Registered: Jul 2018
Posts: 439

Rep: Reputation: 304Reputation: 304Reputation: 304Reputation: 304
Quote:
Originally Posted by errigour View Post
Your right mb that's what I meant but will it work and compile right? i want both structs to be accessed from each other.
Why can't you test this yourself?
 
1 members found this post helpful.
Old 06-07-2024, 07:59 PM   #5
errigour
Member
 
Registered: May 2009
Posts: 373

Original Poster
Rep: Reputation: 6
Quote:
Originally Posted by Mechanikx View Post
Why can't you test this yourself?
I'm not sure even if it works if it's a legal statement and maybe something might be wrong.

Last edited by errigour; 06-07-2024 at 08:01 PM.
 
Old 06-08-2024, 12:16 PM   #6
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,923
Blog Entries: 1

Rep: Reputation: 1885Reputation: 1885Reputation: 1885Reputation: 1885Reputation: 1885Reputation: 1885Reputation: 1885Reputation: 1885Reputation: 1885Reputation: 1885Reputation: 1885
There is an important fact behind it: on the platforms where you can use C, every structure-pointer has the same size (often 32 or 64 bit), so the compiler can handle declarations like `struct NotDefinedYet *ptr` simply reserving space for a structure-pointer.
(Though you won't be able to use `sizeof *ptr` or `ptr->field` until you have defined the struct.)

Last edited by NevemTeve; 06-08-2024 at 12:20 PM.
 
Old 06-09-2024, 09:03 AM   #7
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,820
Blog Entries: 4

Rep: Reputation: 3984Reputation: 3984Reputation: 3984Reputation: 3984Reputation: 3984Reputation: 3984Reputation: 3984Reputation: 3984Reputation: 3984Reputation: 3984Reputation: 3984
https://stackoverflow.com/questions/...x-and#18658591

The “C” language still does not have a strong notion of what we today consider “types.” It is a low-level language: a mere (but, very important…) step above “assembler.” It is always, at its essence, “talking to the hardware.” (Witness the Linux kernel “/arch” subdirectory.)

Contrast with: “C++.” Which, in its original incarnation, was a macro preprocessor.

For any modern “C-style” projects, I invite you to consider “C++.” Unless you are directly concerned with hardware, go ahead and take advantage of the goodness. Notions of “macro preprocessors” are long gone, and the (“gcc …”) language-stack now handles both source languages directly. (Yay!)

Of course, “C++ interfaces” to “plain-C” code (and thence to “asm”) are also well-defined by necessity.

Last edited by sundialsvcs; 06-09-2024 at 09:25 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Cannot get past GDISK- Caution: Invalid backup GPT header, but valid main header, regenerating backup header from main header. murde Linux - Newbie 2 05-30-2020 08:23 PM
c header file to assembler header file Fractal Cat Programming 1 08-12-2017 05:26 PM
How to check missing header files included from another header file adisan82 Linux - Software 1 01-28-2011 03:57 AM
c header files in linux in place of header files in windows? harun_acs Programming 1 03-17-2004 02:24 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:39 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration