[SOLVED] strlen bug?

This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

  • [SOLVED] strlen bug?

    Cant use strlen(stringxx) - always give error too many arguments doesn't matter if I supply singe parameter as constant string or pointer to string
    Any suggestion (if it is not a bug)?
  • If there were a problem in the source, then you would get a build error or warning.

    Remember that all the 'C' language str... functions require a NUL-terminated string to work.

    Again, are you sure that the SES debugger 'Quick Watch' window is even supposed to be able to evaluate the result of a function call? I would guess that it's not.
  • Hello,

    Thank you for your inquiry.
    strlen will not work in the watch window as this is no static variable information. You can use sizeof(variable) though.

    I also tested strlen in source code and it was working as expected. Did you include string.h?

    Best regards,
    Please read the forum rules before posting: Forum Rules

    Keep in mind, this is not a support forum. Its main purpose is user to user interaction.
    Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
    Should you be entitled to support you can contact us via our support system: segger.com/ticket/

    Or you can contact us via e-mail.
  • Thank you for the replies, but even if we forget watch windows - just look on the first snapshot I posted:

    There are couple uint16_t initialized before the breakpoint @150-153:
    lenXX, lenX, lenY, len

    As you can see on the right side the variables that were initialized with the value of a strlen function are even not shown in the list of the Local variables, also the variables that were initialized with 77 and 14 (decimals ), after pass through lines 151-152 with strlen() assignments, now at the breakpoint @158 are shown with some weird values 0x0060 and 0x2000 (hexadecimals)

    And "Yes" - I put string.h even tried both ways "string.h" and <string.h> and if by chance I missed any *.h that is required the project will not be build or at least I havent so far such event when miss some *.h file to finish buid process without error message - is it possible at all?

    P.S. BTW most of the IDEs I worked with, "Watch window" can evaluate even more complex expressions than just result of a simple function, as I remember when I played with this problem I tried and + operation and it was working fine in the SES watch window.
  • What optimisation setting are you using?

    It is possible (even likely) that "useless" variables will be removed by the optimiser, or that their values may not actually be set until "needed"

    I wouldn't expect any IDE's 'Watch' facility to be able to just run an arbitrary function, and display the result.
  • Ok I added couple additions and function calls to trigger variables evaluation, but still getting weird results :(
    Still cant find any logic in the math returned - tomorrow with fresh mind will look it again :(
    One thing only is sure - the Locals Window in debug mode is useless :(
    I havent change any settings from what are defaults - tomorrow will search where is the optimization setting and will see if I can switch it off completely ...
  • I concur with awneil. I have noticed situations where the debugger could do a better job and at catching optimized variables, that are either removed from the tree (compile tree) or only exist in a register. We want those optimizations, so, sometimes they have issues. It has been a long while, when the optimizer chucks out variables optimizes them to register only, I do not know all of what information is left for the debugger to actually find.

    The simplest debugging technique when you are checking out sections of code is to make those variables in question volatile (and or static). Forcing the hand of the compiler to reduce some of the optimizations on those local variables.