1

I know that we can use comments to refer to e.g. methods in java (see this).

Is this option available in c too? Lots of time while commenting, for example, I have a bug that is handled after 10 lines. How can I say to the other developer: "Do not handle it. It's handled on the next 'if()' block"?

int main(){
    int x = 10;
    printf("x = %d\n", x); //don't check if x is more than 18. We will check it in another "if"
    
    //bla bla bla
    //...
    
    if(x >= 18)
        printf("OK we can submit you\n");
    else {
        printf("No. You're too young\n");
        return 1;
    }
}

Mohammad Kholghi
  • 533
  • 2
  • 7
  • 21
  • 1
    FYI, in java that works only when generating the documentation, it doesn't link to the method in the source code. – Federico klez Culloca Feb 17 '22 at 08:31
  • @FedericoklezCulloca Thanks, but this kind of commentings is still usable when we `ctrl`+`click` on the comment in some IDEs. Better than nothing. – Mohammad Kholghi Feb 17 '22 at 08:37
  • Note that these links cannot link to some random line number. You can reference "a module, package, class, or member name", but not to "the code 10 lines down". – Thomas Kläger Feb 17 '22 at 09:13
  • So are you asking if and how a certain IDE can jump to certain locations from a comment in source code? – the busybee Feb 17 '22 at 12:38
  • You can use Javadoc for C sources, with only few limitations. But the common tool is Doxygen that knows many languages. It is quite compatible to Javadoc, if you use "@" instead of "\". – the busybee Feb 17 '22 at 12:40
  • @ThomasKläger What about a special block? Not 10 lines downs, but a special e.g. `while` or `if`, which has a special comment or what. – Mohammad Kholghi Feb 20 '22 at 16:32
  • @thebusybee yes. I use VS Code. I know java supports this feature in commenting, so other IDEs which support java, support this too. – Mohammad Kholghi Feb 20 '22 at 16:33
  • @thebusybee Thanks, but for what I do, I have 2 options: KEIL, VS code. I do microcontroller stuff. – Mohammad Kholghi Feb 20 '22 at 16:33
  • 1
    In JavaDoc the smallest referenceable unit is a "member" of a class: a constructor, a method or a field. You cannot address any smaller unit (i.e. neither line of code nor a block of code within a constructor or method) – Thomas Kläger Feb 20 '22 at 17:30
  • You can use Doxygen with VS code (https://marketplace.visualstudio.com/items?itemName=cschlosser.doxdocgen) and with Keil IDE (https://www.programmerall.com/article/67281040825/) – Thomas Kläger Feb 20 '22 at 17:32

0 Answers0