• Re: compare literals / if( "cat"== "dog") {}

    From Rosario19@[email protected] to comp.lang.c on Thu Oct 15 11:36:34 2026
    From Newsgroup: comp.lang.c

    On Sat, 10 Oct 2026 23:02:54 +0200, fir
    have asked for that but i got somewhat holes im my memory and i
    dont exactly remember sometimes on which i wrote and on which not

    the problem is i need this adhos enums strongly and really, but those
    'smth' are to shore i could use two of them f('some','thin') but it gets >uglier and such code is like degraded

    in fact there could be quite easy solution - it is use string literals
    as such tags - i mean you dont need to use strcomp , you just need to
    have same string literals have same pointer then

    if("cat" == "cat") will return true and
    if("cat" == "dog") will return false

    I say if int is 4 chars this should return 1 in case of fist line
    0 in case the second line

    if((*(int*)"cat") == (*(int*)"cat")) return 1
    if((*(int*)"cat") == (*(int*)"dog") ) return 0

    otherwise there is a need one function that from the pointer check
    strings are ugual as strcmp

    I think can be too
    strcpy(char* a, char* b)
    {
    if(a==b) return 0;

    }

    but who is sure a and b point a to 2 strings?

    i probably asked that but if so once again

    is there way to enforce it to work?

    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Janis Papanagnou@[email protected] to comp.lang.c on Thu Oct 15 12:09:06 2026
    From Newsgroup: comp.lang.c

    On 2026-10-15 11:36, Rosario19 wrote:
    On Sat, 10 Oct 2026 23:02:54 +0200, fir
    have asked for that but i got somewhat holes im my memory and i
    dont exactly remember sometimes on which i wrote and on which not

    the problem is i need this adhos enums strongly and really, but those
    'smth' are to shore i could use two of them f('some','thin') but it gets
    uglier and such code is like degraded

    in fact there could be quite easy solution - it is use string literals
    as such tags - i mean you dont need to use strcomp , you just need to
    have same string literals have same pointer then

    if("cat" == "cat") will return true and
    if("cat" == "dog") will return false

    I say if int is 4 chars this should return 1 in case of fist line
    0 in case the second line

    if((*(int*)"cat") == (*(int*)"cat")) return 1
    if((*(int*)"cat") == (*(int*)"dog") ) return 0

    You are seriously suggesting that the semantics of "C" should
    depend on the actual string-length at runtime, that it should
    not have an unambiguous uniform semantics in the first place?

    Janis


    otherwise there is a need one function that from the pointer check
    strings are ugual as strcmp

    I think can be too
    strcpy(char* a, char* b)
    {
    if(a==b) return 0;

    }

    but who is sure a and b point a to 2 strings?

    i probably asked that but if so once again

    is there way to enforce it to work?


    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Rosario19@[email protected] to comp.lang.c on Fri Oct 16 23:25:59 2026
    From Newsgroup: comp.lang.c

    On Thu, 15 Oct 2026 12:09:06 +0200, Janis Papanagnou wrote:

    On 2026-10-15 11:36, Rosario19 wrote:
    On Sat, 10 Oct 2026 23:02:54 +0200, fir
    have asked for that but i got somewhat holes im my memory and i
    dont exactly remember sometimes on which i wrote and on which not

    the problem is i need this adhos enums strongly and really, but those
    'smth' are to shore i could use two of them f('some','thin') but it gets >>> uglier and such code is like degraded

    in fact there could be quite easy solution - it is use string literals
    as such tags - i mean you dont need to use strcomp , you just need to
    have same string literals have same pointer then

    if("cat" == "cat") will return true and
    if("cat" == "dog") will return false

    I say if int is 4 chars this should return 1 in case of fist line
    0 in case the second line

    if((*(int*)"cat") == (*(int*)"cat")) return 1
    if((*(int*)"cat") == (*(int*)"dog") ) return 0

    You are seriously suggesting that the semantics of "C" should
    depend on the actual string-length at runtime, that it should
    not have an unambiguous uniform semantics in the first place?

    Janis

    no, but see x86 assembly result of above in my pc can do that as
    aspected
    --- Synchronet 3.22a-Linux NewsLink 1.2