A method for generating source code from one or more blocks of a block diagram comprising a model of a dynamic system having at least one signal connection between two blocks, the generating of source code being performed by a processor of a computer system by means of a code generator or in a client-server environment, the block or blocks (B1, B2, B3, B4, B5) of the block diagram being transformed in a first step into an intermediate representation comprising one or more hierarchal graphs, the hierarchal graph or graphs being optimized in a second step, and the optimized intermediate representation in source code being translated into a textual programming language in a third step, the block diagram being able to be executed in order to simulate the dynamic system, all blocks (B1, B2, B3, B4, B5, B21, B22, B23, B24) being permanently held in memory and each block being executed once per time step, block diagrams being hierarchally defined, a block in a higher level being able to comprise a plurality of blocks (B21, B22, B23, B24) in a subordinate level, blocks (B21, B22, B23, B24) of a subordinate level being associated with one block of a higher level, at least one region being defined in the block diagram in which one or more blocks (B1, B2, B3, B4, B5, B21, B22, B23, B24) are present, the block diagram comprising a first block (B1, B2, B3, B4, B5, B21, B22, B23, B24) and a second block (B1, B2, B3, B4, B5, B21, B22, B23, B24), the first block (B1, B2, B3, B4, B5, B21, B22, B23, B24) comprising a first block variable and the second block (B1, B2, B3, B4, B5, B21, B22, B23, B24) comprising a second block variable, each block variable of the block diagram comprising an identifier, characterized in that the block diagram comprises one or more definition blocks (D1, D2, D3), wherein a region is defined by means of a definition block such that the block of the next higher level comprising the definition block and all blocks (B21, B22, B23, B24) associated with said comprising block are present in the region, wherein the identifier of the first block variable is compared with the identifier of the second block variable, wherein it is checked whether the first block (B1, B2, B3, B4, B5, B21, B22, B23, B24) and the second block (B1, B2, B3, B4, B5, B21, B22, B23, B24) are present in the same region, and wherein the first block variable and the second block variable are implemented as one single variable in the source code if the identifiers match and the blocks (B1, B2, B3, B4, B5, B21, B22, B23, B24) are present in one region, and wherein the first block variable and the second block variable are implemented as two separate variables in the source code if the identifiers are different and/or if the blocks (B1, B2, B3, B4, B5, B21, B22, B23, B24) are not present in the same region, wherein each block variable comprises a permissibility marking able to be set or not set, wherein the permissibility marking is implemented as a test marking allowing an optimization only in conjunction with the fulfilling of an additional condition, so that two block variables are implemented in the same variable only if the permissibility marking is set in both block variables and at least one additional associated check condition is met, wherein one or more of the following check conditions are checked: • whether the block variables within the block are not modified, but rather only read out • whether the lifespans of different instances of the block variables are disjoint, so that the two block variables are read or written only at different, nonoverlapping times • whether the block variables in a definition data collection are associated with the same variable definition • whether the block variables are disposed at an identically specified, directed connection. • whether the block variables within the block are not modified, but rather only read out • whether the lifespans of different instances of the block variables are disjoint, so that the two block variables are read or written only at different, nonoverlapping times • whether the block variables in a definition data collection are associated with the same variable definition • whether the block variables are disposed at an identically specified, directed connection.