Csound Csound-dev Csound-tekno Search About

[Csnd-dev] strange string behaviour

Date2025-09-13 15:10
Fromjoachim heintz
Subject[Csnd-dev] strange string behaviour
due to strange problems with an old csd i came to this:

instr 1
   Snew = ""
   Sline = sprintfk("%s%d\n",Snew,1)
   Snew = strcatk(Snew,Sline)
   printf("Sline = \n%s\n",1,Sline)
   printf("Snew = \n%s\n",1,Snew)
   turnoff
endin
schedule(1,0,1)

i expect Sline to be 1 and Snew also.  but as printout shows:
Sline =
1
1
Snew =
1
1
1

am i doing something silly, or what is happening here?

Date2025-09-13 15:35
FromVictor Lazzarini <000010b17ddd988e-dmarc-request@LISTSERV.HEANET.IE>
SubjectRe: [Csnd-dev] [EXTERNAL] [Csnd-dev] strange string behaviour
is printf running at perf time? the string opcodes are "k"
Prof. Victor Lazzarini
Maynooth University
Ireland

> On 13 Sep 2025, at 15:11, joachim heintz  wrote:
> 
> due to strange problems with an old csd i came to this:
> 
> instr 1
>  Snew = ""
>  Sline = sprintfk("%s%d\n",Snew,1)
>  Snew = strcatk(Snew,Sline)
>  printf("Sline = \n%s\n",1,Sline)
>  printf("Snew = \n%s\n",1,Snew)
>  turnoff
> endin
> schedule(1,0,1)
> 
> i expect Sline to be 1 and Snew also.  but as printout shows:
> Sline =
> 1
> 1
> Snew =
> 1
> 1
> 1
> 
> am i doing something silly, or what is happening here?

Date2025-09-14 01:00
Fromjoachim heintz
SubjectRe: [Csnd-dev] [EXTERNAL] [Csnd-dev] strange string behaviour
yes but there is only one cycle because of the turnoff.
so why is it repeating the string?

this code gets the same result although it clearly should only run one 
cycle:
   Snew = ""
   if timeinstk() == 1 then
     Sline = sprintfk("%s%d\n",Snew,1)
     Snew = strcatk(Snew,Sline)
     printf("Sline = \n%s\n",1,Sline)
     printf("Snew = \n%s\n",1,Snew)
   endif

i tried several versions and it has something to do with the line
   Snew = ""

i will try to get closer and then file an issue.

On 13/09/2025 23:35, Victor Lazzarini wrote:
> is printf running at perf time? the string opcodes are "k"
> Prof. Victor Lazzarini
> Maynooth University
> Ireland
> 
>> On 13 Sep 2025, at 15:11, joachim heintz  wrote:
>>
>> due to strange problems with an old csd i came to this:
>>
>> instr 1
>>   Snew = ""
>>   Sline = sprintfk("%s%d\n",Snew,1)
>>   Snew = strcatk(Snew,Sline)
>>   printf("Sline = \n%s\n",1,Sline)
>>   printf("Snew = \n%s\n",1,Snew)
>>   turnoff
>> endin
>> schedule(1,0,1)
>>
>> i expect Sline to be 1 and Snew also.  but as printout shows:
>> Sline =
>> 1
>> 1
>> Snew =
>> 1
>> 1
>> 1
>>
>> am i doing something silly, or what is happening here?

Date2025-09-14 01:15
FromVictor Lazzarini <000010b17ddd988e-dmarc-request@LISTSERV.HEANET.IE>
SubjectRe: [Csnd-dev] [EXTERNAL] [Csnd-dev] strange string behaviour
There is no issue, the printout is what I would have expected.

Snew runs only at i-time, sprintfk/strcatk run at i-time and perf-time, printf only at perf-time.

i-time:
Snew >>>> ""
Sline >>>> "1\n"
Snew >>>> "1\n"

p-time:
Sline >>>> "1\n1\n"
Snew >>>> "1\n1\n1\n"
Sline =
1
1
Snew =
1
1
1
turnoff

Prof. Victor Lazzarini
Maynooth University
Ireland

> On 14 Sep 2025, at 01:01, joachim heintz  wrote:
> 
> yes but there is only one cycle because of the turnoff.
> so why is it repeating the string?
> 
> this code gets the same result although it clearly should only run one cycle:
>  Snew = ""
>  if timeinstk() == 1 then
>    Sline = sprintfk("%s%d\n",Snew,1)
>    Snew = strcatk(Snew,Sline)
>    printf("Sline = \n%s\n",1,Sline)
>    printf("Snew = \n%s\n",1,Snew)
>  endif
> 
> i tried several versions and it has something to do with the line
>  Snew = ""
> 
> i will try to get closer and then file an issue.
> 
>> On 13/09/2025 23:35, Victor Lazzarini wrote:
>> is printf running at perf time? the string opcodes are "k"
>> Prof. Victor Lazzarini
>> Maynooth University
>> Ireland
>>>> On 13 Sep 2025, at 15:11, joachim heintz  wrote:
>>> 
>>> due to strange problems with an old csd i came to this:
>>> 
>>> instr 1
>>>  Snew = ""
>>>  Sline = sprintfk("%s%d\n",Snew,1)
>>>  Snew = strcatk(Snew,Sline)
>>>  printf("Sline = \n%s\n",1,Sline)
>>>  printf("Snew = \n%s\n",1,Snew)
>>>  turnoff
>>> endin
>>> schedule(1,0,1)
>>> 
>>> i expect Sline to be 1 and Snew also.  but as printout shows:
>>> Sline =
>>> 1
>>> 1
>>> Snew =
>>> 1
>>> 1
>>> 1
>>> 
>>> am i doing something silly, or what is happening here?

Date2025-09-14 02:32
Fromjoachim heintz
SubjectRe: [Csnd-dev] [EXTERNAL] [Csnd-dev] strange string behaviour
thank you!
it is confusing to me that sprintfk and strcatk not only run at k-time 
but also at i-time.
but i see now that the problem is in
Snew = ""
which tells csound to run also at i-rate.
it works when i change to
Snew = strcpyk("")


On 14/09/2025 09:15, Victor Lazzarini wrote:
> There is no issue, the printout is what I would have expected.
> 
> Snew runs only at i-time, sprintfk/strcatk run at i-time and perf-time, printf only at perf-time.
> 
> i-time:
> Snew >>>> ""
> Sline >>>> "1\n"
> Snew >>>> "1\n"
> 
> p-time:
> Sline >>>> "1\n1\n"
> Snew >>>> "1\n1\n1\n"
> Sline =
> 1
> 1
> Snew =
> 1
> 1
> 1
> turnoff
> 
> Prof. Victor Lazzarini
> Maynooth University
> Ireland
> 
>> On 14 Sep 2025, at 01:01, joachim heintz  wrote:
>>
>> yes but there is only one cycle because of the turnoff.
>> so why is it repeating the string?
>>
>> this code gets the same result although it clearly should only run one cycle:
>>   Snew = ""
>>   if timeinstk() == 1 then
>>     Sline = sprintfk("%s%d\n",Snew,1)
>>     Snew = strcatk(Snew,Sline)
>>     printf("Sline = \n%s\n",1,Sline)
>>     printf("Snew = \n%s\n",1,Snew)
>>   endif
>>
>> i tried several versions and it has something to do with the line
>>   Snew = ""
>>
>> i will try to get closer and then file an issue.
>>
>>> On 13/09/2025 23:35, Victor Lazzarini wrote:
>>> is printf running at perf time? the string opcodes are "k"
>>> Prof. Victor Lazzarini
>>> Maynooth University
>>> Ireland
>>>>> On 13 Sep 2025, at 15:11, joachim heintz  wrote:
>>>>
>>>> due to strange problems with an old csd i came to this:
>>>>
>>>> instr 1
>>>>   Snew = ""
>>>>   Sline = sprintfk("%s%d\n",Snew,1)
>>>>   Snew = strcatk(Snew,Sline)
>>>>   printf("Sline = \n%s\n",1,Sline)
>>>>   printf("Snew = \n%s\n",1,Snew)
>>>>   turnoff
>>>> endin
>>>> schedule(1,0,1)
>>>>
>>>> i expect Sline to be 1 and Snew also.  but as printout shows:
>>>> Sline =
>>>> 1
>>>> 1
>>>> Snew =
>>>> 1
>>>> 1
>>>> 1
>>>>
>>>> am i doing something silly, or what is happening here?

Date2025-09-14 09:21
Fromvlz
SubjectRe: [Csnd-dev] [EXTERNAL] [Csnd-dev] strange string behaviour
yes, S-types are confusing that way. 


Prof. Victor Lazzarini
Maynooth University
Ireland

> On 14 Sep 2025, at 02:33, joachim heintz  wrote:
> 
> thank you!
> it is confusing to me that sprintfk and strcatk not only run at k-time but also at i-time.
> but i see now that the problem is in
> Snew = ""
> which tells csound to run also at i-rate.
> it works when i change to
> Snew = strcpyk("")
> 
> 
>> On 14/09/2025 09:15, Victor Lazzarini wrote:
>> There is no issue, the printout is what I would have expected.
>> Snew runs only at i-time, sprintfk/strcatk run at i-time and perf-time, printf only at perf-time.
>> i-time:
>> Snew >>>> ""
>> Sline >>>> "1\n"
>> Snew >>>> "1\n"
>> p-time:
>> Sline >>>> "1\n1\n"
>> Snew >>>> "1\n1\n1\n"
>> Sline =
>> 1
>> 1
>> Snew =
>> 1
>> 1
>> 1
>> turnoff
>> Prof. Victor Lazzarini
>> Maynooth University
>> Ireland
>>>> On 14 Sep 2025, at 01:01, joachim heintz  wrote:
>>> 
>>> yes but there is only one cycle because of the turnoff.
>>> so why is it repeating the string?
>>> 
>>> this code gets the same result although it clearly should only run one cycle:
>>>  Snew = ""
>>>  if timeinstk() == 1 then
>>>    Sline = sprintfk("%s%d\n",Snew,1)
>>>    Snew = strcatk(Snew,Sline)
>>>    printf("Sline = \n%s\n",1,Sline)
>>>    printf("Snew = \n%s\n",1,Snew)
>>>  endif
>>> 
>>> i tried several versions and it has something to do with the line
>>>  Snew = ""
>>> 
>>> i will try to get closer and then file an issue.
>>> 
>>>> On 13/09/2025 23:35, Victor Lazzarini wrote:
>>>> is printf running at perf time? the string opcodes are "k"
>>>> Prof. Victor Lazzarini
>>>> Maynooth University
>>>> Ireland
>>>>>> On 13 Sep 2025, at 15:11, joachim heintz  wrote:
>>>>> 
>>>>> due to strange problems with an old csd i came to this:
>>>>> 
>>>>> instr 1
>>>>>  Snew = ""
>>>>>  Sline = sprintfk("%s%d\n",Snew,1)
>>>>>  Snew = strcatk(Snew,Sline)
>>>>>  printf("Sline = \n%s\n",1,Sline)
>>>>>  printf("Snew = \n%s\n",1,Snew)
>>>>>  turnoff
>>>>> endin
>>>>> schedule(1,0,1)
>>>>> 
>>>>> i expect Sline to be 1 and Snew also.  but as printout shows:
>>>>> Sline =
>>>>> 1
>>>>> 1
>>>>> Snew =
>>>>> 1
>>>>> 1
>>>>> 1
>>>>> 
>>>>> am i doing something silly, or what is happening here?