LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 10-17-2018, 06:21 PM   #1
shlomo.hovir
Member
 
Registered: Oct 2018
Posts: 66

Rep: Reputation: Disabled
can somebody explain me what is macro in programming


can somebody explain me what is macro in programming
with pratical examples and layman words

i think and i beleive that they are like the _time_ and the values that are self defined and also the things that are already defined in the libc and ready to be used in programming and without self defining them

am i right?

Last edited by shlomo.hovir; 10-17-2018 at 06:39 PM.
 
Old 10-17-2018, 06:26 PM   #2
shlomo.hovir
Member
 
Registered: Oct 2018
Posts: 66

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by shlomo.hovir View Post
can somebody explain me what is macro in programming
with pratical examples and layman words
i think and i beleive that they are like the _time_ and the values that are self defined and also the things that are already defined in the libc and ready to be used in programming and without self defining them

am i right?

Last edited by shlomo.hovir; 10-17-2018 at 06:31 PM.
 
Old 10-17-2018, 06:58 PM   #3
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,264
Blog Entries: 24

Rep: Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195
A quick search will turn up many useful links, including this Wikipedia article which looks very helpful.

A macro is essentially a short expression or marker which represents a larger block of code. When the macro is found by the language processor it is expanded into its full representation. This makes repetitive use of some code patterns less tedious and error prone, as noted in the above article.

Do you have a specific question about macro use? If so, it would be best to give a simple example of what you have in mind so that others here may provide a specific answer.

Please review the Site FAQ for guidance in asking well formed questions.
 
Old 10-17-2018, 07:07 PM   #4
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
c programming macro
https://www.programiz.com/c-programm...-macros#macros
 
Old 10-17-2018, 07:16 PM   #5
shlomo.hovir
Member
 
Registered: Oct 2018
Posts: 66

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by astrogeek View Post
A quick search will turn up many useful links, including this Wikipedia article which looks very helpful.

A macro is essentially a short expression or marker which represents a larger block of code. When the macro is found by the language processor it is expanded into its full representation. This makes repetitive use of some code patterns less tedious and error prone, as noted in the above article.

Do you have a specific question about macro use? If so, it would be best to give a simple example of what you have in mind so that others here may provide a specific answer.

Please review the Site FAQ for guidance in asking well formed questions.
a macro are self defined things like values contained in libc or header files like _time_ or values of super globals don't know exactly whats their names like $_GET's values in php

Last edited by shlomo.hovir; 10-17-2018 at 07:22 PM.
 
Old 10-17-2018, 07:48 PM   #6
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,264
Blog Entries: 24

Rep: Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195
Quote:
Originally Posted by shlomo.hovir View Post
a macro are self defined things like values contained in libc or header files like _time_ or values of super globals don't know exactly whats their names like $_GET's values in php
No.

Some of those things may be macros, but that is not what macros "are". PHP's $_GET is not a macro.

Please read the linked article and perform your own search to try to find one that you can best understand easily. And read to understand, not so much for quick but incomplete answers.

Perhaps this GNU cpp documentation may be more helpful with specific examples.

Last edited by astrogeek; 10-17-2018 at 07:59 PM.
 
Old 10-17-2018, 08:29 PM   #7
shlomo.hovir
Member
 
Registered: Oct 2018
Posts: 66

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by astrogeek View Post
No.

Some of those things may be macros, but that is not what macros "are". PHP's $_GET is not a macro.

Please read the linked article and perform your own search to try to find one that you can best understand easily. And read to understand, not so much for quick but incomplete answers.

Perhaps this GNU cpp documentation may be more helpful with specific examples.

macros are the only those who are used with #ifdef and #if
 
Old 10-17-2018, 08:32 PM   #8
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,864
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
Originally, term 'macro-instruction' meant 'user-defined instruction' in Assembly, e.g.:
Code:
MACRO       ; define a macro
MY_LD_DE_HL ; name of the macro
LD E,(HL)
INC HL
LD D,(HL)
DEC HL
MEND        ; end of definition
...
LD HL,(someptr)
MY_LD_DE_HL ; use the macro

Last edited by NevemTeve; 10-18-2018 at 02:04 AM. Reason: comments
 
Old 10-17-2018, 11:43 PM   #9
shlomo.hovir
Member
 
Registered: Oct 2018
Posts: 66

Original Poster
Rep: Reputation: Disabled
are macros specifically a definition of something to be used for conditional compiling

after a search of 2 weeks i have found that is that true

http://i.imgur.com/ytm2Azn.png
 
Old 10-18-2018, 01:09 AM   #10
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,264
Blog Entries: 24

Rep: Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195
Please post your thread only once. Posting a single thread in the most relevant forum will make it easier for members to help you and will keep the discussion in one place. Your new thread has been merged with this previous thread of the same general topic.

I will also ask you again to refrain from posting links to offsite resorces as the primary content of your posts. This behavior is not an acceptable use of the LQ Programming forum.

I again ask you to please review the Site FAQ for guidance in posting your questions and general forum usage.
 
Old 10-18-2018, 02:08 AM   #11
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,864
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
(Luckily, the OP has already found out what macros are, so no more answers are required.)
 
Old 10-18-2018, 03:11 AM   #12
shlomo.hovir
Member
 
Registered: Oct 2018
Posts: 66

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by NevemTeve View Post
(Luckily, the OP has already found out what macros are, so no more answers are required.)

still didn't get it completly

[QUOTE= circumference = radius * 2 * pi;
The macro is called "circumference"

So, whenever you call the macro "circumference" the word is replaced with the whole contents of the text.

Exactly the same as in any text editor with macros.
[/QUOTE]

why would anyone substitue a variable with a value???
 
Old 10-18-2018, 03:36 AM   #13
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,864
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
Please edit your post to make it more readable. Also please specify what programming language are you thinking of.
 
Old 10-18-2018, 04:15 AM   #14
shlomo.hovir
Member
 
Registered: Oct 2018
Posts: 66

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by NevemTeve View Post
Please edit your post to make it more readable. Also please specify what programming language are you thinking of.
my language is c
can u tell me why would someone use macros in c for substiuate a variable with a value
 
Old 10-18-2018, 04:52 AM   #15
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,864
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
Please edit your post#12 to make it more readable. Also please check if it has any #define in it -- if it is C-language and we are talking about macros, I would expect to see some #define-s.
 
  


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
Programming in M4 macro; quotation issue BenJZ Programming 1 05-27-2014 05:02 AM
explain eof in c programming. batman4 Programming 7 02-07-2013 09:20 AM
Could someone please explain the concept of associative arrays in AWK programming? AJAY E Linux - Newbie 6 05-27-2012 07:01 PM
C: programming macro recorder and pixel reader ganyks Programming 4 12-02-2009 08:04 AM

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

All times are GMT -5. The time now is 10:59 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