cvideohevc

Backslash in c source file


I have follow code same as it is on different lines:

frame_rate = (float)
                ( ( ( frames * media_timescale) + \   //WHY???
                    ( media_duration >> 1 ) ) /
                 media_duration);

I am not understanding what is backslash doing in source file ? Also to calculate the frame rate simply we can do as follow:

frame_rate = (float) ( (  frames * media_timescale) / media_duration);

Is there any specific intention to write first type of code?


Solution

  • It's a line-continuation escape. It means the compiler will consider the next line as a part of the current line.

    It makes the code you show in practice being

    frame_rate = (float)
                    ( ( ( frames * media_timescale) + ( media_duration >> 1 ) ) /
                     media_duration);
    

    There's no real need for it in this case though, except as maybe some style-guide followed by the author had it as a requirement.

    Line continuation is needed to define "multi-line" macros, and are also often used for long strings. But besides those places, it serves no real purpose.