LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
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 08-24-2018, 10:56 AM   #1
bkelly
Member
 
Registered: Jan 2008
Distribution: Centos 7-4
Posts: 205

Rep: Reputation: 13
Recursive define in C++


A code file declares a procedure in this manner:
Code:
CONDITIONALPROC(FFProcessDerivedFunctions,(char*)"")
{...}
There is a define that begins with
Code:
#define CONDITIONALPROC(name,args) extern "C" ConditionalProc CONDITIONALPROC##name;  char * ....
The ellipsis indicates that this one line carries on for much longer but this question is limited to two points.
1. This looks recursive. Please explain how that works in defines.
2. What is the significance of the ## that precedes "name;"

Last edited by bkelly; 08-24-2018 at 10:59 AM. Reason: typo
 
Old 08-24-2018, 12:16 PM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,838

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
I won't tell you the solution, just suggest you to try: g++ -E source.cpp > source.e
and check the content of that file.
I hope that will help you to understand.
 
Old 08-24-2018, 01:28 PM   #3
bkelly
Member
 
Registered: Jan 2008
Distribution: Centos 7-4
Posts: 205

Original Poster
Rep: Reputation: 13
I tried that with the complaint that an include file could not be found. The output file did not go far enough to get to the point of interest. This is an include file of a larger application. It has a make file with eight lines and a two critical lines appear to be

Code:
PROG1_SOURCES=tam_main.cpp
include $(ROO_DIR)/make.rules
make.rules is a file of 1443 lines of text and is far beyond my expertise. A search for "g++" and "gcc" in the Makefile and the make.rules was not productive. What might be changed to cause g++ to save the preprocessor output file?
 
Old 08-24-2018, 01:53 PM   #4
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,838

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
there can be a macro specifying the flags, for example CPPFLAGS. But also you may try to set make to print commands as they executed and you will need to copy that command and add -E.
 
Old 08-24-2018, 08:46 PM   #5
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,780

Rep: Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081
Quote:
Originally Posted by bkelly View Post
1. This looks recursive.
Self-Referential Macros

Quote:
2. What is the significance of the ## that precedes "name;"
Concatenation
 
Old 08-28-2018, 11:49 AM   #6
bkelly
Member
 
Registered: Jan 2008
Distribution: Centos 7-4
Posts: 205

Original Poster
Rep: Reputation: 13
I took the suggestions and wrote some code using that macro, discovering that it is not recursive. The first instance of CONDITIONALPROC is replaced by the contents of the define and that ends the replacement. The macro creates three lines of code and the final contains a procedure name prefixed with CONDITIONALPROC. The purpose of that is so that a custom scripting language can easily recognize the function name and parse it out. We do telemetry work and that custom script language is used to translate between various file formats.
I found it complicated because I still have not figured out how to get the Makefile to keep the preprocessor output somewhere. And that is complicated by multiple include files from multiple directories.

Maybe this question will help me.


The makefile and the code that it builds is located here:
Code:
/users/home/bkelly/repo/MCS/src/MCC/TAM/main
The last line in the Makefile is:
Code:
include $(ROOT_DIR)/make.rules
file make.rules is located here:
Code:
/users/home/bkelly.repo/MCS/make.rules
So to enable a local build I think I need to set something like an environment variable, name it ROOT_DIR and its value should be something like:
Code:
/users/home/bkelly/repo/MCS
So I did
Code:
man setenv
and saw that then I tried this command line entry

Code:
setenv ROOT_DIR /users/home/bkelly/repo/MCS
the reply was:
Code:
bash: setenv: command not found.
What am I not recognizing?
 
Old 08-28-2018, 02:07 PM   #7
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,862
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
Either:
Code:
make ROOT_DIR=/users/home/bkelly/repo/MCS all
or
Code:
ROOT_DIR=/users/home/bkelly/repo/MCS make all
 
Old 08-28-2018, 03:35 PM   #8
bkelly
Member
 
Registered: Jan 2008
Distribution: Centos 7-4
Posts: 205

Original Poster
Rep: Reputation: 13
I am missing something here. Am I to understand that the environment variable ROOT_DIR cannot be set with a separate and specific operation and that it must be a command line argument used when I start the make process?
I am a Linux novice and probably miss what is obvious to you.
 
Old 08-28-2018, 07:56 PM   #9
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,780

Rep: Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081
Quote:
Originally Posted by bkelly View Post
I am missing something here. Am I to understand that the environment variable ROOT_DIR cannot be set with a separate and specific operation
It cannot be set by a separate executable, because each process has its own set of environment variables (child processes inherit the initial environment from their parent).

Quote:
and that it must be a command line argument used when I start the make process?
You could also set it before, with export (this is a shell builtin command, not a separate executable):
Code:
export ROOT_DIR=/users/home/bkelly/repo/MCS
make all
It's usually better not to though. When you do the setting as part of starting the process, you see it right there, and won't get surprised by some setting you made earlier in the session and forgot about.

References:
GNU Bash: Bourne Shell Builtins, export.
GNU Make: How Variables Get Their Values
 
Old 08-30-2018, 10:16 AM   #10
bkelly
Member
 
Registered: Jan 2008
Distribution: Centos 7-4
Posts: 205

Original Poster
Rep: Reputation: 13
Re: When you do the setting as part of starting the process ...
Yes, that is the best approach.
To each of you, thanks for your time.
 
  


Reply



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
How do I define a unique label in a #define macro? schmitta Programming 1 05-08-2014 07:23 AM
mv not recursive? BeacoN Linux - General 7 10-10-2012 06:46 AM
Help with a #define Wynd Programming 4 04-22-2007 03:30 PM
m4 define in a define Four Programming 0 03-04-2007 09:41 PM
rm -r what is recursive wogga Linux - Software 3 05-28-2004 02:29 PM

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

All times are GMT -5. The time now is 01:30 PM.

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