EEVblog Electronics Community Forum

Electronics => Projects, Designs, and Technical Stuff => Topic started by: Jester on March 23, 2022, 01:34:47 pm

Title: C language backslash
Post by: Jester on March 23, 2022, 01:34:47 pm
Can someone tell me the significance of the backslash at the end of the first line in this define in a c language header file?

The preceding comment is also confusing,  I'm not sure what they are trying to convey with the \b

//*****************************************************************************
//
// Macro to call SysCtl_delay() to achieve a delay in microseconds. The macro
// will convert the desired delay in microseconds to the count value expected
// by the function. \b x is the number of microseconds to delay.
//
//*****************************************************************************
#define DEVICE_DELAY_US(x) SysCtl_delay(((((long double)(x)) / (1000000.0L /  \
                              (long double)DEVICE_SYSCLK_FREQ)) - 9.0L) / 5.0L)

Title: Re: C language backslash
Post by: Ed.Kloonk on March 23, 2022, 01:42:39 pm
It's called an escape sequence and it is masking the newline from the compiler so that the two lines appear as one line to the compiler and it's used to provide a bit of readability to the coder instead of one gigantic long line of code.
Title: Re: C language backslash
Post by: mon2 on March 23, 2022, 01:42:47 pm
The details should be available on all C language websites but..

It means that this line is continued onto the next. That is, treat the line that follows and this line as a single line of code.
Title: Re: C language backslash
Post by: Jester on March 23, 2022, 02:06:30 pm
It's called an escape sequence and it is masking the newline from the compiler so that the two lines appear as one line to the compiler and it's used to provide a bit of readability to the coder instead of one gigantic long line of code.

Thanks, your explanation is better than the google hits I read.

What do you make of the \b in the preceding comment?
Title: Re: C language backslash
Post by: DavidAlfa on March 23, 2022, 02:07:15 pm
It means it should countinue parsing the next line like if it was the current one.
Ex.
Code: [Select]
if ((a==0x1234) && (b==0xAA55) && (c==1 || d!=0)){
}

Code: [Select]
if (  (a==0x1234) &&  \
      (b==0xAA55) &&  \
      (c==1 || d!=0) ){
}
Title: Re: C language backslash
Post by: Ed.Kloonk on March 23, 2022, 02:17:09 pm
It's called an escape sequence and it is masking the newline from the compiler so that the two lines appear as one line to the compiler and it's used to provide a bit of readability to the coder instead of one gigantic long line of code.

Thanks, your explanation is better than the google hits I read.

What do you make of the \b in the preceding comment?

Don't know.

Mon2 explained it with less words. Ironic that my reply needed to be chopped up itself.

You see a lot of the \  in bash scripts. You often need to break up unwieldy bash one-liners otherwise no hacker could ever understand the code.
Title: Re: C language backslash
Post by: PaulAm on March 23, 2022, 02:18:40 pm
It is not needed in regular C statements.  It's used in the original example because it is in a #define statement and macros are defined in a single line.  The backslashes are used in that case to make it more readable
Title: Re: C language backslash
Post by: retiredfeline on March 23, 2022, 02:22:36 pm
The \b is in a comment so doesn't affect the C code. My guess is it's a directive to a program that extracts documentation from block comments before functions, and \b might mean bold the next word or something like that.
Title: Re: C language backslash
Post by: RoGeorge on March 23, 2022, 02:35:07 pm
Doxygen is a software tool to automatically build documentation by using the comment lines found inside the source files. 

"\b" in Doxygen is to print the next word with bold font in the doc pages
https://www.doxygen.nl/manual/commands.html#cmdb (https://www.doxygen.nl/manual/commands.html#cmdb)
Title: Re: C language backslash
Post by: Ed.Kloonk on March 23, 2022, 02:41:33 pm
Ah.