Monday, December 3, 2012

Computing Makefile variable on assignment - Stack Overflow


In a Makefile, I'm trying to assign the result of a shell command to a variable:
TMP=`mktemp -d /tmp/.XXXXX`

all:
    echo $(TMP)
    echo $(TMP)
but
$ make Makefile all
is echoing 2 different values, eg:
/tmp/.gLpm1T
/tmp/.aR4cDi
What is the syntax for mktemp to be computed on variable assignment?
Thank you.
share|improve this question

57% accept rate
Was this post useful to you?     

3 Answers


up vote10down voteaccepted
It depends on the flavour of make. With GNU Make, you can use := instead of = as in
TMP:=$(shell mktemp -d /tmp/.XXXXX)
Edit As pointed out by Novelocrat, the = assignment differs from := assignment in that values assigned using = will be evaluated during substitution (and thus, each time, the variable is used), whereas := assigned variables will have their values evaluated only once (during assignment), and hence, the values are fixed after that. See the documentation of GNU Make for a more detailed explanation.
In order for the value to be truelly constant after assignment, though, the it should not contain any parts, which might be special to the shell (which make calls in order to actually run the update rules, etc.) In particular, backticks are best avoided. Instead, use GNU make's built-in shell function and similar to achieve your goals.
share|improve this answer
Variables assigned with = are evaluated at each substitution. Variables assigned with := are evaluated at assignment, as you desire. – Novelocrat Sep 16 '09 at 22:37
Hi Dirk, It does not seem to work: pastie.org/619606 Is there a syntax error in my Makefile? Thanks – abernierSep 16 '09 at 23:04
Edited answer again. I think, the problem is the use of the backticks; for make, the value (incl. the backticks) is essentially "constant" and will get pasted as is at the point of use -- and then, the backticks will be seen by the shell at each point of use. Just a theory, though. – Dirk Sep 16 '09 at 23:12
Ok, finally found solution, thanks to you and your link: I have to use := for assignment operator, but also $(shell mktemp -d /tmp/.XXXXX) It works now, thank you so much! – abernier Sep 16 '09 at 23:16
I've accepted your answer, please add the $(shell ) tip ;) – abernier Sep 16 '09 at 23:17
feedback


Computing Makefile variable on assignment - Stack Overflow

'via Blog this'

Interesting Information about protecting yourself legally, YMMV | The Law Office of Drew K. Baumchen, LLC

Information and Frequently Asked Questions About

  Criminal Cases from a Former Deputy District Attorney

...
Common Questions (FAQ's):

What to Do If You Have Been Contacted By the Police or Think You are Being Investigated

If you have been approached or questioned by a police officer, the first thing to ask yourself is: why is this law-enforcement person talking to me?  The sad reality today is that, in most instances, when a police officer approaches you or questions you, he is not looking to help you or be your friend.  The police officer is there because you have done something that has aroused their attention and they think that you may be committing or have already committed an offense or crime.  So, the best thing you can do to help yourself and try to stay out of trouble is REFUSE TO TALK TO THE POLICE OFFICER OR INVESTIGATOR.  Do not answer any questions or allow them to search you or "pat you down" in any way.
We've all heard of "The Right to Remain Silent" and that "anything you say can and will be used against you in court."  Well, believe it or not, it's true:  If you decide to speak to a police officer or investigator without an attorney present and end up getting charged with a crime or offense, you will probably hear them testify about what you said to them.  Even worse, your statements can be taken out of context or they may even put words in your mouth.  You can rest assured, however, that a police officer is almost never allowed to say in court that the defendant exercised the right to remain silent.  If you want to help the police officer or investigator investigate you by talking to them, that's your choice.  I, however, suggest that you tell them that you want to remain silent and talk to an attorney.  If the officer persists, don't give in--tell them you are not going to speak to them without an attorney present.  And then give us a call as soon as possible.

What Happens After You've Been Arrested or Cited

If you were arrested for a criminal charge and are reading this information online, then you have probably posted bail or security to get out or have been released either conditionally or on your own recognizance ("recogged" or "ROR'd").  (NOTE: if you are visiting my site for a friend or family member who is in jail, please contact my office immediately so that I can help try to secure their release as soon as possible.)  If the police officer or other government agent gave you a "ticket" instead of arresting you then you were issued a citation (or cited) to appear in court.  In either case, you should have received a date, time, and place for your court appearance.
Whether you were given a citation or were arrested and got out of jail before seeing a judge, your next court appearance is usually called an arraignment.  Sometimes, an arraignment can be as soon as the morning of the next day.  At the arraignment, the judge will read the charges against you and advise you of your trial rights.  The judge may also address your release conditions (such as whether you can leave the state, have any contact with the alleged victim in the charge, use or possess alcohol, return to your home, etc.).  You will be given the opportunity to apply for a public defender, if you wish (click here for more information about public defenders).  Sometimes the court will enter a "Not Guilty" plea on your behalf as a matter of procedure.  This is normal.  In other courts you will not be asked to plead guilty or not guilty until much later in the case.  It is very important NOT to plead "Not Guilty" at your arraignment unless the judge asks you to--doing so will usually just annoy or anger the judge.  I also suggest that you do not plead "Guilty" or "No Contest" at your arraignment without first speaking with an experienced criminal defense attorney.  If you plead "Guilty" or "No Contest" at your arraignment, you may be giving up your right to fight your case forever.
If you were cited into court, the District Attorney or prosecutor will sometimes ask that you report to the jail for a "book and release."  This means that you will have to go to the jail after court (or sometimes within 48-72 hours of your arraignment) to have your fingerprints and mugshot taken.  You will not be arrested or taken into custody on a "book and release." 
After your arraignment, you will be given another court date, normally about three to five weeks out (except in most felony cases.  For more information about felony cases, scroll down).  Depending on the court and type of case, this next date will be called a Pre-Trial Conference, Entry of Plea, 35-day Call, or just Call.  Whatever the name is, this next appearance is a check-in or status conference on your case.  In some courts, it may be scheduled just a day or two before your first trial date.  In others, you may not even have a trial scheduled yet.  No matter what, this is the latest point in your case by which you should have contacted an attorney.  If you originally thought you could "go it alone" without an attorney, hopefully you have changed your mind by now or are at least willing to consult with an experienced criminal defense lawyer before going any further.

Special Information for Felony Cases

There are many special legal and procedural rules for felony cases and not enough room to explain them all here.  One basic procedure I will discuss, however, is the grand jury.  A grand jury is a group of seven jurors (occasionally less) that hold a secret proceeding where they review the evidence in the case that is presented by the District Attorney.  When a person is charged with a felony, the case is usually presented to a grand jury either before or after the first arraignment.  The grand jury does not decide whether the defendant is guilty or not guilty.  The role of the grand jury is to determine whether there is enough evidence in the case to even proceed with the charges (if so, the grand jury issues what is called an "indictment").  Historically, the grand jury was used as a safeguard to prevent prosecutors from filing felony charges that were frivolous or politically-motivated.  Unfortunately, today the grand jury is more of just a routine step in the process than an actual procedural safeguard.  It is very unusual for a grand jury to not issue an indictment on a case that the District Attorney has presented.  Also, because the grand jury is sworn to secrecy and its members are not allowed to discuss the cases or proceedings, there are few ways to be sure that the prosecutors are presenting the evidence fairly.
When the grand jury meets before the defendant's arraignment, they usually issue what is called a "secret indictment."  A secret indictment remains in a hidden court file and does not become a public record until the defendant is arrested or otherwise appears in court on the charge(s).  When a grand jury issues a secret indictment, they also usually issue an arrest warrant for the defendant.  Unfortunately, this process usually means that the defendant is not aware of the charge(s) until it's too late and often prevents them from turning themselves in or voluntarily appearing in court on the charge.  An experienced criminal defense attorney can sometimes create an open line of communication with the District Attorney and may be able to prevent the defendant from being arrested in this manner by making arrangements for the defendant to turn themselves into the police or voluntarily appear in court.
If you have been charged or arrested for a felony, you should contact an experienced criminal defense attorney to discuss your case.  The sooner you get an attorney on your side, the more that attorney can do to help you with your case.

When You Will be Able to Tell the Judge or Jury Your Side

When someone first appears in court on a criminal charge, they often think "if I just tell the judge what happened, he or she will understand and will..." (dismiss the case, give you a warning, etc.).  Unfortunately, this is not how things usually work.  The arraignment or first appearance on a case is generally not the appropriate time to try and explain your side of things.  In fact, trying to do so will probabjust make the judge annoyed or angry.  The reality is, you will probably not have the opportunity to explain what happened in your case until your trial or if you decide to plead guilty to the charge(s).  However, an experienced criminal defense lawyer will listen to your side of the case and can talk with you about how and when it will benefit you to explain your side of things in court, or if it will really even help your case to explain your side at all.  Most important, an experienced criminal defense attorney knows how to effectively communicate for you with judges, jurors, and prosecutors and can help you put your best foot forward.

Will You Go to Jail if You are Convicted?

Whether you will go to jail or not if you are convicted is difficult to say and depends on a variety of factors.  Some of these factors are: your previous criminal record (if any), the nature and type of offense, whether you have a job and what sort of work you do, whether you support a family, whether you take a plea deal or go to trial, and many others.  The criminal justice system provides many alternatives to jail for those who qualify, such as: electronic monitoring or electronic home detention ("EHD" or the "ankle bracelet"), work-release programs, or community service.  An experienced criminal defense attorney can discuss these options with you and negotiate with the prosecutor or District Attorney to try to resolve your case in a way that minimizes the jail time you may have to serve or avoids your having to serve any jail time at all.

Do You Really Need a Criminal Defense Lawyer?

There's an old saying that goes something like: "A person who acts as their own lawyer has a fool for a client."  Under our constitution, you have an absolute right to represent yourself without a lawyer in any criminal case.  That doesn't mean it's a very good idea, though.  Even the most simple criminal cases involve complex rules and procedures that are confusing and overwhelming to most people.  Even worse, most judges are not going to "give you a break" if you decide to represent yourself--they will expect you to know the laws and rules that apply to your case and won't often give you a chance to figure it out or have a "do-over."  If you tried to proceed with representing yourself in court already, the judge probably "suggested" that you speak with an attorney and gave you a stern lecture about what a lawyer can do to help you.  Hopefully, you listened to what the judge told you because it's true.  It is never advisable to try to handle a criminal case on your own without at least consulting an experienced criminal defense lawyer.

How to Choose a Lawyer

Choosing the right lawyer for your case can be a challenge.  In my opinion, the best lawyer for you is: 1) a lawyer who you feel comfortable is competent to handle your type of case; 2) a lawyer who you feel you can trust and truly has your best interests at heart; 3) a lawyer that you can understand and communicate clearly with; and 4) a lawyer who is honest with you about your legal fees and costs for your defense.
Almost all lawyers advertise in some fashion.  Flip open the yellow pages and you will find lots of fancy, full-page ads for criminal defense and DUI lawyers.  You should never choose a lawyer by who has the biggest or brightest ad in the phone book because most ads tell you very little about the lawyer's qualifications or experience.  The best way to find a criminal defense lawyer is to ask your friends or family if they can refer you to a lawyer that they know or have heard of.  If you know someone who is a police officer or works in law-enforcement, call them and ask who they would recommend.  Even better, if you have an attorney for family or business matters, or just a friend who a lawyer or judge, ask them for a referral.  Even though there are a lot of lawyers in Portland and around the state, it is still a relatively small legal community and most lawyers can refer you to a reputable attorney for your specific type of case.  Lawyers and judges are generally the best evaluators of the qualifications and experience of other lawyers.
Also, you shouldn't be afraid to meet or consult with several lawyers before making a decision on who to hire.  By meeting with more than one attorney, you will be able to compare and contrast your experience during the consultation and will probably have a better idea of which lawyer is going to be best for you and your case.  Most criminal defense and DUI lawyers don't charge for an initial consultation, so you don't have much to lose by shopping around.  To contact The Law Office of Drew K. Baumchen for a free consultation for your criminal case, please click here.*

How Much Will a Criminal Defense Lawyer Cost?

Like most things in life, when it comes to lawyers, you usually will end up paying for what you get.  To be perfectly honest with you, good lawyers are certainly not cheap.  However, even minor criminal cases can be very serious and a conviction can have dramatic repercussions for your life, your job, and your family.  Trying to go "low-budget" with a criminal defense attorney may end up in "low-budget" results. 
Every case is different, so it's tough to say how much your legal fees would be for your case or even for your type of case.  At The Law Office of Drew K. Baumchen, LLC, I try to work with my clients to find cost-effective solutions to their cases, whether it's litigating the case and going to trial, or aggressively negotiating with the prosecutor or District Attorney to work toward a settlement or plea agreement.  Depending on your financial circumstances, an initial retainer for my services can be as little as $1,000.  I generally take criminal cases on a flat-fee or fee-per-service basis.  When I am deciding how much my fee will be for a case or for a particular service, I try to estimate how many hours of work the case or service will require.  Then, I calculate my fees by using the estimated number of hours and the type of case and work involved.  For most cases, my minimum hourly fee is $200-250 per hour, again depending on the type of case and work involved.  I feel that these rates are fair and reasonable because of my experience, my level of personal service to my clients, and rates that other lawyers with similar skill and experience charge.  Additionally, I try to make it a point not to "nickel and dime" my clients for the little things, like quick phone calls, emails, or photocopies.  I believe that this adds value to the fees my clients pay and further justifies my minimum hourly rates.
To find out how much it will cost to hire experienced criminal defense lawyer Drew K. Baumchen for your specific case, please contact my office to set up a free initial consultation.*

What Happens if You Can't Afford a Lawyer

If you can't afford a lawyer, you may qualify to have a public defender represent you in your criminal case.  While many public defenders are excellent lawyers, even the best can sometimes be overworked or defending too many cases to present the very best defense in each case.  When you hire a lawyer to represent you in a criminal case, one of the things that you are paying for is a higher level of personal service.  Most privately retained criminal defense attorneys will spend more time with you and will be able to greater address your specific concerns and individual circumstances.
Another major difference between a privately retained attorney and a public defender is that you can not get a public defender until you have actually been charged with a crime and appeared in court.  Often, this is well past the point where a criminal defense attorney can have the most effective impact on the outcome of your case.  An experienced criminal defense lawyer can provide early intervention in a criminal case and assist you before any charges are filed, and sometimes they can help prevent any charges from being filed at all.
A criminal conviction can have serious consequences for your life, your job, and your family.  If you have been investigated, charged, or arrested for a criminal offense and you think you can't afford a criminal defense lawyer, think about your future and contact The Law Office of Drew K. Baumchen, LLC today.

Glossary of Legal Terms

Consult or Consultation: a meeting between a prospective lawyer and potential client in which the client can explain their legal issue and the facts of their case so the lawyer can evaluate the case, discuss the client's legal position, and talk about the cost to hire the lawyer. 
Criminal Defense Lawyer (or Criminal Defense Attorney): an attorney who specializes in criminal cases and who has specialized knowledge of criminal laws and procedures.  A criminal defense lawyer also usually has significant courtroom and trial experience.
Criminal Charge (or Offense): an allegation by the government that a person has violated a law that prohibits certain conduct as being a crime.  Generally, criminal charges are more serious than non-criminal charges because a criminal charge may result in the defendant going to jail or prison.
District Attorney (or DA): in Oregon, the District Attorney is the government lawyer who prosecutes most criminal cases.  In most counties, there are Deputy District Attorneys who work for the District Attorney in the District Attorney's Office.  Often, the term District Attorney or "DA" is used to refer to the prosecutor or Deputy District Attorney assigned to a particular case.
Felony: a felony is a serious criminal charge that could result in the defendant going to jail, prison, or worse if they are convicted.  A felony is generally defined as any offense for which the maximum penalty can be more than one year in jail.
Grand Jury: a grand jury is a group of seven citizens (sometimes less) who are asked to review felony charges to determine whether there is enough evidence to proceed with the case.  Grand juries meet privately and are sworn to secrecy about the cases that they review and the evidence that they hear.
Guilty Plea: an admission that the defendant committed a specific crime or offense that they are charged with.  Usually, a guilty plea also involves admitting to the particular facts of the crime or offense.
Misdemeanor: a misdemeanor is a lower-level offense that can still be very serious.  Misdemeanors are commonly defined as any offense for which the maximum penalty is no more than one year in jail.
No Contest Plea: a plea of no contest is similar to a guilty plea except that the defendant does not have to admit to the particular conduct that constitutes the offense.  Either way, the defendant ends up convicted of the offense.  While a defendant has an absolute right to plead guilty to any charge at any time, a court or judge is not required to accept a plea of no contest in a criminal case.
Not Guilty: a finding by a judge or jury that there is not enough evidence to convict a defendant of a particular charge.  Not guilty is different from innocent because not guilty simply means that the evidence in the case was legally insufficient to confirm the defendant's guilt.
Warrant: a warrant is a judge's command, usually either to arrest a person (arrest warrant) or to search a particular place or thing (search warrant).  Arrest warrants are frequently entered into a police database so that police officers will know if a person they are speaking to has a warrant out for their arrest (in which case the police officer will arrest them).  A search warrant is different in that search warrants are generally executed shortly after they are issued by a judge.

* The Law Office of Drew K. Baumchen, LLC offers free initial consultations to potential clients who have been arrested or charged with a criminal offense.  I also generally provide free initial consultations to potential clients who are or reasonably believe they are being investigated by the police or other government agency for a crime or other offense.  I occasionally charge consultation fees in criminal cases where a potential client has already been convicted of an offense, or is seeking relief from a judgment or court order.


... More at the following link.  [This is not legal advice, blah blah blah, I just found some of the details interesting, Cheers, Connie]

The Law Office of Drew K. Baumchen, LLC | Information about criminal cases and defense

'via Blog this'

Sunday, December 2, 2012

When Nomadic Matt's Roommate **** in His Hostel/Dorm Room, ah, memories... | Nomadic Matt's Travel Site



P.S. He still likes the hostel...  I guess everyone likes experiences that give them good stories to tell, or just that create vivid memories that last a lifetime (or until you can somehow scrub them out of your brain :-)  )...

My Hostel Horror Story: When My Roommate Shit in Our Dorm Room

By Nomadic Matt | Published October 30th, 2012
look of horror and shockOver the years, I’ve had some bad hostel roommates. They’ve been rude, messy, dirty, smelly, drunk, loud and everything in between. Two girls in New Zealand were so bad they inspired me to write a post on hostel etiquette. But through it all, I’ve kept staying at hostels. I love hostels because of their gregarious social atmosphere. Hotels seem too sterile when compared with the energy and camaraderie of hostels. As I’ve gotten older, more set in my ways, and have become a lighter sleeper, I often think to myself “Why do I stay in dorm rooms? I’m so over them,” but then book one more night because I don’t want to pay extra for a private room. (Though I do get out of hostels and into hotels when I need a work break).
But that feeling changed when I had the shittiest roommate of all time. Hostel dorm rooms and I are now on an indefinite break.
Let me explain why (and warn you now that I wouldn’t be eating while you read this):
It all began on a lovely Barcelona Monday morning in September. I was enjoying a nice sleep, dreaming one of my typical surrealist dreams – dreams that have me being Batman one moment and escaping aliens on ancient clipper ships in another. Awoken by a loud banging from using my superpowers to fight bad guys, I looked at my phone – 7:30 am. The banging from the door continued. Groggy from sleep, I woke up, wished someone else had heard the noise instead of me, got out of bed, and opened the door. My Brazilian dorm mate standing in his towel said “Sorry” and rushed into the room.
This was the latest event on a long list of weekend rudeness. I was traveling with my friendKiersten and we had been staying four nights in a dorm with this Brazilian and his friend. They snored, turned the lights on at night, came home drunk, talked loudly, proposed marriage to Kiersten, and were very messy. We were happy to be checking out of the room that day.
After letting the Brazilian in, I went back to my bed, and just as I was about to lay down, caught an odious whiff of something. “What is that smell? Why does it smell like shit?” I said to myself. I looked everywhere and couldn’t place it. I hadn’t pooped myself in my sleep. Being still half asleep only added to my confusion.
“What is going on?”
I was perplexed.
Then I smelled my hand.
“Why does my hand smell like shit?” I thought.
I was now even more confused. I got back up and turned on the lights to the dorm.
And that’s when I noticed it – I had shit on my hand.
Because there was shit on the door handle.
And a poop trail back to the large Brazilian’s bed.
I stared in shock at my hand and turned to him. Catching my gaze, he looked at me and said “I just got in, dude. I just got in!!!” He was playing dumb.
Now I understood why he was showering so early in the morning – he had shit himself, touched the doorknob on the way to the bathroom (in what I can only hope was a drunken accident because who would do that on purpose!?), and locked himself out of the room, leaving me as the unfortunate roommate to open the door. One can only imagine the reaction (eardrum shattering shrieks) if one of the girls in the dorm had been the unfortunate one.
“I just got in, dude,” was all he kept saying to me, trying to pretend that he wasn’t clearly the cause of this mess.
“You shit yourself in bed and then grabbed the door handle! That is fucking disgusting! And just rude!” I swore, horrified and disgusted by this whole event.
I ran to the bathroom and sanitized the crap out of my hand (pun intended). I scrubbed to what felt like the bone. Grabbing a roll of toilet paper, I walked back to the room, noticed a dirty mattress outside the room, and opened the door.
The trail of shit to the bed was gone but the inner door knob was not clean. “It wasn’t me,” the Brazilian guy said, trying to prove his innocence despite being caught in the act of cleaning the scene of the crime. Disgusted, I cleaned the doorknob myself, using all my remaining hand sanitizer and toilet paper.
I went back and washed my hands again, and then again, and then once more for good measure.
As I went back to the room, I looked into the dorm next door as the door was wide open. Not a bed was missing. Inside my dorm, the Brazilian had fallen into a drunken sleep on a mattress. To this day, I still don’t know where that mattress in the hall came from. My roommate had managed to find a clean mattress somehow.
Back in my newly cleaned room, I sat back down on my bed and tried to sleep a little more.
Kiersten, who was in the dorm above me, didn’t believe me when I told her this story later in the morning, but upon seeing a missed poop stain on the floor and a brown hand print on my dorm curtain (which I innocently grabbed before I knew what was on my hand and ripped off my bed after I knew), she freaked out and exclaimed, “Thank god we are checking out today.”
As we left the hostel that day, I hailed a cab.
“The W Hotel,” I said.
As I stepped into the cab, I was never more happy I had decided the night before to move from a hostel to a hotel because, now, a shit-free future, lay ahead of me.
P.S. – I’m not naming the hostel because it is a really good one and I had a great time there. This could have happened to anyone in any dorm in the world.
P.P.S – There were curtains on the bunk beds so people wouldn’t wake up and light was already coming into the room from the poorly shaded window so I wasn’t worried about waking anyone up.

If you're traveling soon, please consider visiting my resources page and use the booking linksthere. It will help keep this website running and advertiser free at no extra cost to you! :)

My Hostel Horror Story: When My Roommate Shit in Our Dorm Room | Nomadic Matt's Travel Site

'via Blog this'

Other built-in functions provided by GCC, from: Using the GNU Compiler Collection (GCC)


5.44 Other built-in functions provided by GCC

GCC provides a large number of built-in functions other than the ones mentioned above. Some of these are for internal use in the processing of exceptions or variable-length argument lists and will not be documented here because they may change from time to time; we do not recommend general use of these functions.
The remaining functions are provided for optimization purposes.
GCC includes built-in versions of many of the functions in the standard C library. The versions prefixed with __builtin_ will always be treated as having the same meaning as the C library function even if you specify the `-fno-builtin' option. (@xref{C Dialect Options}) Many of these functions are only optimized in certain cases; if they are not optimized in a particular case, a call to the library function will be emitted.
The functions abort, exit, _Exit and _exit are recognized and presumed not to return, but otherwise are not built in. _exit is not recognized in strict ISO C mode (`-ansi', `-std=c89' or `-std=c99')._Exit is not recognized in strict C89 mode (`-ansi' or `-std=c89').
Outside strict ISO C mode, the functions alloca, bcmp, bzero, index, rindex, ffs, fputs_unlocked, printf_unlocked and fprintf_unlocked may be handled as built-in functions. All these functions have corresponding versions prefixed with __builtin_, which may be used even in strict C89 mode.
The ISO C99 functions conj, conjf, conjl, creal, crealf, creall, cimag, cimagf, cimagl, llabs and imaxabs are handled as built-in functions except in strict ISO C89 mode. There are also built-in versions of the ISO C99 functions cosf, cosl, fabsf, fabsl, sinf, sinl, sqrtf, and sqrtl, that are recognized in any mode since ISO C89 reserves these names for the purpose to which ISO C99 puts them. All these functions have corresponding versions prefixed with __builtin_.
The ISO C89 functions abs, cos, fabs, fprintf, fputs, labs, memcmp, memcpy, memset, printf, sin, sqrt, strcat, strchr, strcmp, strcpy, strcspn, strlen, strncat, strncmp, strncpy,strpbrk, strrchr, strspn, and strstr are all recognized as built-in functions unless `-fno-builtin' is specified (or `-fno-builtin-function' is specified for an individual function). All of these functions have corresponding versions prefixed with __builtin_.
GCC provides built-in versions of the ISO C99 floating point comparison macros that avoid raising exceptions for unordered operands. They have the same names as the standard macros ( isgreater,isgreaterequal, isless, islessequal, islessgreater, and isunordered) , with __builtin_ prefixed. We intend for a library implementor to be able to simply #define each standard macro to its built-in equivalent.

Built-in Function: int __builtin_types_compatible_p (type1, type2)
You can use the built-in function __builtin_types_compatible_p to determine whether two types are the same. This built-in function returns 1 if the unqualified versions of the types type1 and type2 (which are types, not expressions) are compatible, 0 otherwise. The result of this built-in function can be used in integer constant expressions. This built-in function ignores top level qualifiers (e.g., const, volatile). For example, int is equivalent to const int. The type int[] and int[5] are compatible. On the other hand, int and char * are not compatible, even if the size of their types, on the particular architecture are the same. Also, the amount of pointer indirection is taken into account when determining similarity. Consequently, short * is not similar to short **. Furthermore, two types that are typedefed are considered compatible if their underlying types are compatible. An enum type is considered to be compatible with another enum type. For example, enum {foo, bar} is similar to enum {hot, dog}. You would typically use this function in code whose execution varies depending on the arguments' types. For example:
 
#define foo(x)                                                  \
  ({                                                           \
    typeof (x) tmp;                                             \
    if (__builtin_types_compatible_p (typeof (x), long double)) \
      tmp = foo_long_double (tmp);                              \
    else if (__builtin_types_compatible_p (typeof (x), double)) \
      tmp = foo_double (tmp);                                   \
    else if (__builtin_types_compatible_p (typeof (x), float))  \
      tmp = foo_float (tmp);                                    \
    else                                                        \
      abort ();                                                 \
    tmp;                                                        \
  })
Note: This construct is only available for C.


Built-in Function: type __builtin_choose_expr (const_exp, exp1, exp2)
You can use the built-in function __builtin_choose_expr to evaluate code depending on the value of a constant expression. This built-in function returns exp1 if const_exp, which is a constant expression that must be able to be determined at compile time, is nonzero. Otherwise it returns 0. This built-in function is analogous to the `? :' operator in C, except that the expression returned has its type unaltered by promotion rules. Also, the built-in function does not evaluate the expression that was not chosen. For example, if const_exp evaluates to true, exp2 is not evaluated even if it has side-effects. This built-in function can return an lvalue if the chosen argument is an lvalue. If exp1 is returned, the return type is the same as exp1's type. Similarly, if exp2 is returned, its return type is the same as exp2. Example:
 
#define foo(x)                                                               \
  __builtin_choose_expr (__builtin_types_compatible_p (typeof (x), double),  \
    foo_double (x),                                                          \
    __builtin_choose_expr (__builtin_types_compatible_p (typeof (x), float), \
      foo_float (x),                                                         \
      /* The void expression results in a compile-time error             \
         when assigning the result to something.  */                     \
      (void)0))
Note: This construct is only available for C. Furthermore, the unused expression (exp1 or exp2 depending on the value of const_exp) may still generate syntax errors. This may change in future revisions.


Built-in Function: int __builtin_constant_p (exp)
You can use the built-in function __builtin_constant_p to determine if a value is known to be constant at compile-time and hence that GCC can perform constant-folding on expressions involving that value. The argument of the function is the value to test. The function returns the integer 1 if the argument is known to be a compile-time constant and 0 if it is not known to be a compile-time constant. A return of 0 does not indicate that the value is not a constant, but merely that GCC cannot prove it is a constant with the specified value of the `-O' option. You would typically use this function in an embedded application where memory was a critical resource. If you have some complex calculation, you may want it to be folded if it involves constants, but need to call a function if it does not. For example:
 
#define Scale_Value(X)      \
  (__builtin_constant_p (X) \
  ? ((X) * SCALE + OFFSET) : Scale (X))
You may use this built-in function in either a macro or an inline function. However, if you use it in an inlined function and pass an argument of the function as the argument to the built-in, GCC will never return 1 when you call the inline function with a string constant or compound literal (see section 5.20 Compound Literals) and will not return 1 when you pass a constant numeric value to the inline function unless you specify the `-O' option. You may also use __builtin_constant_p in initializers for static data. For instance, you can write
 
static const int table[] = {
   __builtin_constant_p (EXPRESSION) ? (EXPRESSION) : -1,
   /* ... */
};
This is an acceptable initializer even if EXPRESSION is not a constant expression. GCC must be more conservative about evaluating the built-in in this case, because it has no opportunity to perform optimization. Previous versions of GCC did not accept this built-in in data initializers. The earliest version where it is completely safe is 3.0.1.


Built-in Function: long __builtin_expect (long exp, long c)
You may use __builtin_expect to provide the compiler with branch prediction information. In general, you should prefer to use actual profile feedback for this (`-fprofile-arcs'), as programmers are notoriously bad at predicting how their programs actually perform. However, there are applications in which this data is hard to collect. The return value is the value of exp, which should be an integral expression. The value of c must be a compile-time constant. The semantics of the built-in are that it is expected that exp == c. For example:
 
if (__builtin_expect (x, 0))
  foo ();
would indicate that we do not expect to call foo, since we expect x to be zero. Since you are limited to integral expressions for exp, you should use constructions such as
 
if (__builtin_expect (ptr != NULL, 1))
  error ();
when testing pointer or floating-point values.


Built-in Function: void __builtin_prefetch (const void *addr, ...)
This function is used to minimize cache-miss latency by moving data into a cache before it is accessed. You can insert calls to __builtin_prefetch into code for which you know addresses of data in memory that is likely to be accessed soon. If the target supports them, data prefetch instructions will be generated. If the prefetch is done early enough before the access then the data will be in the cache by the time it is accessed. The value of addr is the address of the memory to prefetch. There are two optional arguments, rw and locality. The value of rw is a compile-time constant one or zero; one means that the prefetch is preparing for a write to the memory address and zero, the default, means that the prefetch is preparing for a read. The value locality must be a compile-time constant integer between zero and three. A value of zero means that the data has no temporal locality, so it need not be left in the cache after the access. A value of three means that the data has a high degree of temporal locality and should be left in all levels of cache possible. Values of one and two mean, respectively, a low or moderate degree of temporal locality. The default is three.
 
for (i = 0; i < n; i++)
  {
    a[i] = a[i] + b[i];
    __builtin_prefetch (&a[i+j], 1, 1);
    __builtin_prefetch (&b[i+j], 0, 1);
    /* ... */
  }
Data prefetch does not generate faults if addr is invalid, but the address expression itself must be valid. For example, a prefetch of p->next will not fault if p->next is not a valid address, but evaluation will fault if p is not a valid address. If the target does not support data prefetch, the address expression is evaluated if it includes side effects but no other code is generated and GCC does not issue a warning.

Using the GNU Compiler Collection (GCC)

'via Blog this'